|
|
|
|
![]() ![]() |
Aug 2 2008, 07:59 PM
Post
#1
|
|
|
Super Member 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? |
|
|
|
Aug 2 2008, 08:10 PM
Post
#2
|
|
|
Super Member 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.
|
|
|
|
Aug 3 2008, 11:58 AM
Post
#3
|
|
|
Way Out Of Control - You need a life :) 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
|
|
|
|
Aug 3 2008, 01:34 PM
Post
#4
|
|
|
Super Member Group: [HOSTED] Posts: 752 Joined: 12-July 06 From: Ontario, Canada Member No.: 14,464 |
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. How often you use it depends on what you usualy do 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. |
|
|
|
Aug 4 2008, 09:06 AM
Post
#5
|
|
|
Way Out Of Control - You need a life :) Group: [HOSTED] Posts: 1,091 Joined: 2-August 05 From: Kapellen (Antwerp, Belgium) Member No.: 7,585 |
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]*>
|
|
|
|
Aug 4 2008, 03:55 PM
Post
#6
|
|
|
Super Member 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. |
|
|
|
Aug 7 2008, 02:24 AM
Post
#7
|
|
|
Advanced Member Group: [MODERATOR] Posts: 142 Joined: 8-January 08 Member No.: 27,477 myCENTs:32.43 |
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. |
|
|
|
![]() ![]() |
Similar Topics
|
Lo-Fi Version | Time is now: 5th December 2008 - 11:37 AM |