Welcome Guest ( Log In | Register )



 
Reply to this topicStart new topic
> Regular Expressions
FirefoxRocks
post Aug 2 2008, 07:59 PM
Post #1


Super Member
Group Icon

Group: [HOSTED]
Posts: 752
Joined: 12-July 06
From: Ontario, Canada
Member No.: 14,464



In PHP and many other programming languages, I have heard of this powerful syntax called RegEx, or regular expressions. It allows you to find strings that match a certain pattern.

I had to use a regex expression to search for a specific string of text within a block of text once, and someone told me to use a regular expression. The example that they wrote worked, although it was extremely confusing and I didn't know what it meant.

http://www.regular-expressions.info/ gives a great tutorial on regular expressions, the syntax and stuff. I'm not sure if this is worth learning. Is it?

How often do I have to use regular expressions? They seem to be really powerful? Is it worth the time to figure them out?
Go to the top of the page
 
+Quote Post
toby
post Aug 2 2008, 08:10 PM
Post #2


Super Member
Group Icon

Group: Members
Posts: 555
Joined: 29-September 06
Member No.: 16,228



You'll probably be learning PCRE regex, orignally from Perl. Regex is very powerful, but one of the slowest general use functions in php. You really should learn if if you can, it's very language-independant. If you look at www.php.net/preg_match (php called it preg, others called it regex) for an explanation of how the regex patterns are used. I found the website you linked to quite hard at first, but the language I used had a much simpler explanation elsewhere. Php may do, you could google for one.
Go to the top of the page
 
+Quote Post
wutske
post Aug 3 2008, 11:58 AM
Post #3


Way Out Of Control - You need a life :)
Group Icon

Group: [HOSTED]
Posts: 1,091
Joined: 2-August 05
From: Kapellen (Antwerp, Belgium)
Member No.: 7,585



How often you use it depends on what you usualy do smile.gif . I personally think that knowing how to use regular expressions is a good thing, they can realy save a lot of time when you are looking for something (eg. when searching a mysql database). Some programs (like Notepad++) allow you to use regular expressions when searching something in a file, very handy tongue.gif
Go to the top of the page
 
+Quote Post
FirefoxRocks
post Aug 3 2008, 01:34 PM
Post #4


Super Member
Group Icon

Group: [HOSTED]
Posts: 752
Joined: 12-July 06
From: Ontario, Canada
Member No.: 14,464



QUOTE(toby @ Aug 2 2008, 03:10 PM) *
You'll probably be learning PCRE regex, orignally from Perl. Regex is very powerful, but one of the slowest general use functions in php. You really should learn if if you can, it's very language-independant. If you look at www.php.net/preg_match (php called it preg, others called it regex) for an explanation of how the regex patterns are used. I found the website you linked to quite hard at first, but the language I used had a much simpler explanation elsewhere. Php may do, you could google for one.

Yes, I believe that the version I'm learning is PCRE regex, or at least that is what I'm testing it on anyways. The PHP page only explained how to use the function a few basic examples like word boundaries and negated searching.

QUOTE(wutske @ Aug 3 2008, 06:58 AM) *
How often you use it depends on what you usualy do smile.gif . I personally think that knowing how to use regular expressions is a good thing, they can realy save a lot of time when you are looking for something (eg. when searching a mysql database). Some programs (like Notepad++) allow you to use regular expressions when searching something in a file, very handy tongue.gif

I realize that Notepad++ has an option for finding text using a regular expression, but it doesn't work. The site linked above gave a few (commercial) programs that use regular expressions to "save time and work". I guess that knowing how to use regular expressions is very useful in validating forms such as email addresses and stuff, and also as wutske stated, for searching databases.
Go to the top of the page
 
+Quote Post
wutske
post Aug 4 2008, 09:06 AM
Post #5


Way Out Of Control - You need a life :)
Group Icon

Group: [HOSTED]
Posts: 1,091
Joined: 2-August 05
From: Kapellen (Antwerp, Belgium)
Member No.: 7,585



QUOTE(FirefoxRocks @ Aug 3 2008, 03:34 PM) *
Yes, I believe that the version I'm learning is PCRE regex, or at least that is what I'm testing it on anyways. The PHP page only explained how to use the function a few basic examples like word boundaries and negated searching.
I realize that Notepad++ has an option for finding text using a regular expression, but it doesn't work. The site linked above gave a few (commercial) programs that use regular expressions to "save time and work". I guess that knowing how to use regular expressions is very useful in validating forms such as email addresses and stuff, and also as wutske stated, for searching databases.


Strange, I've used regular expressions in notepad++ before and it does work.

Quickly write a simple html page in Notepad++ :
CODE
<html>
    <head>
        <title>Hello dude</title>
    </head>
    
    <body>
        <h1>This is a very rudimentary webpage</h1>
        <p>Some custom content</p>
    </body>
</html>


And use the following regular expression to find all html tags (without attributes that is).
CODE
<[A-Za-z][A-Za-z0-9]*>
Go to the top of the page
 
+Quote Post
FirefoxRocks
post Aug 4 2008, 03:55 PM
Post #6


Super Member
Group Icon

Group: [HOSTED]
Posts: 752
Joined: 12-July 06
From: Ontario, Canada
Member No.: 14,464



It didn't work on an HTML page, but it worked in an XML document.

So I guess with arbitrary text support, regular expressions really are useful.
Go to the top of the page
 
+Quote Post
docduke
post Aug 7 2008, 02:24 AM
Post #7


Advanced Member
Group Icon

Group: [MODERATOR]
Posts: 142
Joined: 8-January 08
Member No.: 27,477
myCENTs:32.43



QUOTE(wutske @ Aug 4 2008, 02:06 AM) *
And use the following regular expression to find all html tags (without attributes that is).
CODE
<[A-Za-z][A-Za-z0-9]*>

I guess what you mean depends on what "all html tags" means. I don't think your regex will find any closing tags. I'm barely fluent in regex, but I suspect you really wanted <[A-Za-z\/][A-Za-z0-9]*>, where I have "quoted" the forward slash, in case it is treated as a special character within the regex. What makes things like this really confusing is that some "ordinary" characters, like period, have special meanings. smile.gif
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Request To Upgrade(1)
  2. Regular Used Terms In The Webhosting World(4)
  3. Php Regular Expressions(11)
  4. Megatsunamis(9)
  5. Difference Between Starter And Regular(3)
  6. Airtel GPRS(23)
  7. Any Active & Regular Vietnamese Member At Astahost ?(3)
  8. Announcement: Importance Of Regular Site Backups !(18)
  9. How To Remove Query String Using Regular Expressions(4)
  10. The Absolute Bare Minimum Every Programmer Should Know About Regular Expressions(1)
  11. Filtering Out Unwanted Junk Mail Using Regular Expression.(0)
  12. Regular Expressions Not Matching(4)
  13. Using Regular Expressions To Parse Functions(6)


 



- Lo-Fi Version Time is now: 5th December 2008 - 11:37 AM