E1M1 8 Posted January 13, 2012 Does anyone know if it's possible to write regex pattern where so that \2 would be "I am url" ? Currently it's \4. If I replace ((http|https|news|ftp)://(.*?)) with (.*?) then it works as I want (\2 is "I am url"). I would like to know if it's possible to write such pattern which would still require http|https|news|ftp at the beginning but which would give "I am url" as 2nd match instead of 4th $SEARCH = '\[url\="((http|https|news|ftp)://(.*?))"\](.*?)\[\/url\]' $REPLACE = '<a href="\1">\2</a>' $STR = '[url="http://google.com"]I am url[/url]' ConsoleWrite(StringRegExpReplace($STR,$SEARCH,$REPLACE)&@CRLF) edited Share this post Link to post Share on other sites
JohnQSmith 40 Posted January 13, 2012 Does anyone know if it's possible to write regex pattern where so that 2 would be "I am url" ? Currently it's 4. If I replace ((http|https|news|ftp)://(.*?)) with (.*?) then it works as I want (2 is "I am url"). I would like to know if it's possible to write such pattern which would still require http|https|news|ftp at the beginning but which would give "I am url" as 2nd match instead of 4th You need to add " ?: " to the second and third matching group (parentheses) so that they become non-matching groups. This turns the fourth group into the second group and your regex works as you'd like. $SEARCH = '[url="((?:http|https|news|ftp)://(?:.*?))"](.*?)[/url]' $REPLACE = '<a href="1">2</a>' $STR = '[url="http://google.com"]I am url[/url]' ConsoleWrite(StringRegExpReplace($STR,$SEARCH,$REPLACE)&@CRLF) Whenever someone says "pls" because it's shorter than "please", I say "no" because it's shorter than "yes". Share this post Link to post Share on other sites
E1M1 8 Posted January 13, 2012 Thank you very much. edited Share this post Link to post Share on other sites