#1
  1. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Posts
    853
    Rep Power
    11

    Regular Expression to find the first occurence of a word in the string..


    Lets say I have this string

    firstpartfhttp://domainabc.comhttp://domainxyz.comand this goes on

    I need to find the first full domain in this starting with http:// and ending in com
    When I search for http://.*.[com] in TextPad, I get the result as

    http://domainabc.comhttp://domainxyz.com
    But I want the result to be
    http://domainabc.com
    Please help
    Contact info:
    Primary email: advanced.programmer@gmail.com
    MSN/email: superprg@hotmail.com
    AIM: superprg
  2. #2
  3. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,069
    Rep Power
    9398
    You can't know for sure what the URL is.
    Code:
    firstparthttp://domain.com.comstuff
    domain.com? domain.com.com?

    How about just one domain and one TLD?
    Code:
    http://([a-z]([a-z0-9-]*[a-z0-9])?\.(com|net|org))

    Comments on this post

    • superprogrammer agrees : Thanks for regular expression help!
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Posts
    853
    Rep Power
    11
    Thanks but this doesnt seems to work in TextPad!
    Contact info:
    Primary email: advanced.programmer@gmail.com
    MSN/email: superprg@hotmail.com
    AIM: superprg
  6. #4
  7. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,069
    Rep Power
    9398
    Originally Posted by superprogrammer
    Thanks but this doesnt seems to work in TextPad!
    Then TextPad doesn't support that kind of expression.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Posts
    853
    Rep Power
    11
    TextPad mostly supports POSIX Extended Regular Expression syntax if that helps!
    Contact info:
    Primary email: advanced.programmer@gmail.com
    MSN/email: superprg@hotmail.com
    AIM: superprg
  10. #6
  11. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,069
    Rep Power
    9398
    As far as I can see it is POSIX compatible. TextPad doesn't seem to support what I'm doing.
    Things to check:
    - Supports character sets using ranges
    - Supports the * and ? wildcards
    - Supports alternation using a |
    - Supports capturing subpatterns
    Start with a small part of the expression. Try it. Begin adding parts of the full expression to what you have until it doesn't work.
    Trial and error.

    I tested it against "firstpartfhttp://domainabc.comhttp://domainxyz.comand" and it works fine for me.
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Posts
    853
    Rep Power
    11
    <<I tested it against "firstpartfhttp://domainabc.comhttp://domainxyz.comand" and it works fine for me.>>
    You mean in textpad?
    Contact info:
    Primary email: advanced.programmer@gmail.com
    MSN/email: superprg@hotmail.com
    AIM: superprg
  14. #8
  15. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,069
    Rep Power
    9398
    Not in TextPad but using something that specifically supports POSIX expressions.
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Posts
    853
    Rep Power
    11
    ok Thanks
    I didnt now we have to enable POSIX expression in Textpad
    When I did that by going to
    Configure->Preferences-> Check ' Use POSIX regular expression syntax’
    everything seems to work fine
    Thanks requinix!
    Contact info:
    Primary email: advanced.programmer@gmail.com
    MSN/email: superprg@hotmail.com
    AIM: superprg

IMN logo majestic logo threadwatch logo seochat tools logo