Helpful Information
 
 
Category: Regex Programming
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

You can't know for sure what the URL is.

firstparthttp://domain.com.comstuff
domain.com? domain.com.com?

How about just one domain and one TLD?

http://([a-z]([a-z0-9-]*[a-z0-9])?\.(com|net|org))

Thanks but this doesnt seems to work in TextPad!

Thanks but this doesnt seems to work in TextPad!
Then TextPad doesn't support that kind of expression.

TextPad mostly supports POSIX Extended Regular Expression syntax if that helps!

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.

<<I tested it against "firstpartfhttp://domainabc.comhttp://domainxyz.comand" and it works fine for me.>>
You mean in textpad?

Not in TextPad but using something that specifically supports POSIX expressions.

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!










privacy (GDPR)