I’ve been having trouble making a regular expression which changes “_” to ” “. For example the string below:
<h2><a href=?ref=ref_url&?title=title_name_unoriginal>7s6s**title_name_unoriginal**7s6s<h2>
I’d like to change the starred text so that the underscores become spaces. I added 7s6s so that I could identify that region in a regular expression:
/7s6s[a-zA-Z0-9_]+7s6s/
So I was wondering if anyone knows of a way to change title_name_unoriginal to title name unoriginal. Note: there’s a title_name_unoriginal that comes right before which I don’t want to change. Also for the regex, the number of underscores can be from 0-100s. so it may also be title_name_un_ori_ginal.
Its pretty simple what is doing; first it takes all the texts that start and end with 7s6s (regex: 7s6s.+7s6s), then because the function replace accepts a function as a second argument to perform the replacement, we can make a replacement over the selected text. In this case is just another regex that replaces “_” with ” “