Nov 21, 2009

Regular Expressions

free web hosting
Open Discussion & Free Web Hosting > Computers & Tech > Programming

Regular Expressions

FirefoxRocks
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?

Comment/Reply (w/o sign-up)

toby
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.

Comment/Reply (w/o sign-up)

wutske
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

Comment/Reply (w/o sign-up)

FirefoxRocks
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.

 

 

 


Comment/Reply (w/o sign-up)

wutske
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]*>

Comment/Reply (w/o sign-up)

FirefoxRocks
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.

Comment/Reply (w/o sign-up)

docduke
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

Comment/Reply (w/o sign-up)

x0rk
Perl regex is the most powerful and best regex to learn... I write website scrapers using perl regex... smile.gif

Comment/Reply (w/o sign-up)

PureHeart
In short, regex is a must for those dealing with text processing. Some of its popular applications include form validation (client side with JavaScript and server side with PHP), text parsing, etc.

One more thing, regex is actually very simple. It was covered in a 30 minute lecture at my university. Is there anyone here interested in learning regex? (I can post a tutorial then)

Comment/Reply (w/o sign-up)


Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

This textarea will convert to Rich-Text automatically (IE, Firefox, Chrome)

Similar Topics

Keywords : Regular Expressions


    Looking for regular, expressions

See Also,

*SIMILAR VIDEOS*
Searching Video's for regular, expressions
advertisement



Regular Expressions

Affordable Web Hosting, Low cost Web Hosting - ComputingHost.com