SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Evangelist barbara1712's Avatar
    Join Date
    Apr 2007
    Location
    India
    Posts
    508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    regular expression

    Hello All,

    Guys,I want to use regular expressions like preg_replace,preg_match,etc.
    But I am poor at regular expressions.i.e.I always get confused how to write the
    pattern.I got no of examples for reg.exp. .
    But still I am getting confused while writing pattern.
    So can anyone help me how do I write pattern or easiest way to write pattern.

    Your help will be highly appriciated.
    Thanks,
    Barbara

  2. #2
    SitePoint Enthusiast
    Join Date
    Mar 2002
    Location
    Whistler, Canada
    Posts
    51
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi barbara,

    These two websites proved extremely useful to me when I started with regular expressions:
    Regex tutorial
    RegExLib

    Good luck

    Cheers,
    Pepe

  3. #3
    SitePoint Evangelist barbara1712's Avatar
    Join Date
    Apr 2007
    Location
    India
    Posts
    508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks a lot IP-Dope,
    I started to study the first link.It helped me a lot.
    But in the part ,I have studied so far,I did not get one thing.It may be
    nothing for you.But I want help.
    In some example the symbol '^' (caret) is used as negation.But in some examples it is used as the start of string.Like

    Applying ^a to abc matches a. ^b will not match abc at all, because the b cannot be matched right after the start of the string, matched by ^.

    The difference I noticed that it '^' if appears in square bracket ,it works as negation and if outside the square bracket as in above example in bold will work as start of string.
    I could be wrong.But I want to confirm.

    Thanks IP-Dope,
    Barbara

  4. #4
    SitePoint Enthusiast
    Join Date
    Mar 2002
    Location
    Whistler, Canada
    Posts
    51
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey Barbara,

    Good job, that's definitely the case. If you use the caret metachar outside a character class ([abc] for instance is a character class) it is used for the start of a string. Putting a caret inside the character class is negation.

    Cheers,
    Pepe

  5. #5
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This may be helpful too: http://www.cuneytyilmaz.com/prog/jrx/

  6. #6
    SitePoint Zealot
    Join Date
    Aug 2005
    Posts
    122
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here is a nice video about them, this helped to push me from the "i kinda get it.." to "this is stupid easy" ...

    http://e-texteditor.com/blog/2007/re...sions_tutorial

    And if your editor supports regex searching, its a great tool for setting up regexs. The editor in the above link is e. Its based on textmate from mac so its pretty sweet...but the great thing it does is has "live" searching (like firefox, as you type it highlights results) ... this makes it really easy to test regexs, just by typing what you want to match, then using the search untill you actually match it. That turned out to be the best tool for me to learn with, and now I really have no problems at all using regex patterns.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •