Regex recruit needs help
source link: https://www.codesd.com/item/regex-recruit-needs-help.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Regex recruit needs help
I'm totally useless at regex, any advice much appreciated.
$url = 'http://somedomain.com?var=<##var##>&var2=<##var2##>';
echo preg_replace('^<##(.*)##>$', '', $url);
Trying to strip anything between (and including) <## and ##>. So my result would be:
http://somedomain.com?var=&var2=
Thanks
The code should be:
<?php
$url = 'http://somedomain.com?var=<##var##>&var2=<##var2##>';
$newUrl = preg_replace('/<##.*?##>/', '', $url);
echo $url;
?>
The ^
and $
you used are wrong, they represend the begin or the end of the string and you won't replace only the <##...##>
part if <##
is at the beginning and ##>
at the end of the string.
Also the ?
after .*
means that it matches everything from the <##
until the next ##>
. If you use .*
it matches everything from the first <##
until the last ##>
so you result would be http://somedomain.com?var=
Related Articles
Need help getting parts of an RSS feed using Regex
Need help with (hopefully) simple RegEx
I need help decoding this regular expression of the sprockets
Need help with the sql query to find things labeled with all the specified tags
I need help with a SQL query JOINT JOIN
Java: Need help reporting NullPointerException
Need help writing a custom attribute in MVC
Need help optimizing the oracle query
I need help understanding the manipulation of the character
Need help for complex data to sort SQL Server
Need help with forming a regular expression -xml
Need help repositioning and resizing widgets with the Python Tkinter grid
Need help creating lead or corner divisions CSS / HTML
Program file (x86) when checked for dwfileattributes Returns a value of 73745. I need help knowing what combination is added to this value?
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK