RegEx Search & Replace (via Dreamweaver CS5) - regex

I have to deal with a problem and maybe you can help.
I took over a Website with a lot of code and would like to have it run on PHP 5.4.
But there are a LOT of statement's like this:
if($arrayname['keyname']>"") ....
I would like to replace them all with:
if(!empty($arrayname['keyname'])) ....
Doing it manually will take forever :-(
Do you know how to use Dreamweaver's CS5 search & replace with RegEx capabilites - unfortunately my RegEx knwoledge is limited.
Of course the regex must be "variable, as the arrayname and the keyname always changes.
Any help on finding the correct RegEx Stamtent is HIGHLY appreciated .

Regex to find all occurrences of if($arrayname['keyname']>""), whatever arrayname and keyname are, if only letters :
if\\(\\$[a-zA-Z]*\\[\'[a-zA-Z]*\'\\]>\"\"\\)
You'll have to find how to use BackReferences in Dreamweaver. If it uses standard Regex, then use the tutorial in the link, it will be of great help for you.

To complete and close this question:
In Dreamweaver search for (Regex Search in Code):
if\(\$(\w+)\[['"](\w+)['"]\]>""\)
Replace by:
if(!empty($$1['$2']))

Related

REGEX - Conditional replacement stopping to match when I choose the new string

I have a lot of developer's name like this:
/Ramon/ /Cesar/ /Murilo/ /Tiago/
I would like to apply a conditional regex to replace every name with just its first letter.
So when it matches /Ramon/ it would become /r/, /Cesar/ turn into /c/...
I'm trying to achive it here: https://regex101.com/r/rTlS1k/3
With no success.
Appreciate any help.
Thanks.
Assuming you are using PCRE based on your regex101, then search for:
/\/(\w)[^\/]+\//g
and replace with
/\L\1/
As seen here: https://regex101.com/r/ZDQlEY/1

Regex to match everything."LettersNumbers"."extension" and forum searching tip

I would need a regex to match my files named "something".Title"numberFrom1to99".mp4 on Windows' File Explorer, my first approach as a regex newbie was something like
"..mp4"
, but it didn't work, so i tried
"*.Title[1-9][0-9].mp4"
, that also did not work.
I would also like a tip on how to search regex related advices on Stackoverflow archive but also on the web, so that i can be specific, but without having the regex in the searching bar interact.
Thank you!
EDIT
About the second part of the question: in the question itself there is written "..mp4" but i wrote "asterisk"."asterisk".mp4, is there any universal way to write regex on the web without it having effect and without escaping the characters? (in that way the backslash shows inside the regex, and that could be misunderstood)
Try something like this:
(.*)\.[A-za-z]+\d+\.mp4
See this Regex Demo to get an explanation on the regex.
Use regex101.com to test your regexs
Here it is:
^[\s\S]*\.Title[1-9][0-9]?\.mp4$
I suggest regexr.com to find many interesting regexes(Favourites tab) and simple tutorial.
About the second part of the question: in the question itself there is written "..mp4" but i wrote "asterisk"."asterisk".mp4, is there any universal way to write regex on the web without it having effect and without escaping the characters? (in that way the backslash shows inside the regex, and that could be misunderstood)

Notepad++ Wildcard Find/Replace

I'm using Notepad++ and need to update a file where there are various differences in earlier sections of the string of text and think Wildcards may help here. From the research I've done thus far, it isn't clear what syntax would be used for this.
Here's an example of the original string:
"EEID","SUPLIFE","Voluntary Life Insurance","500000.00","500000.00",0,276,10.62.0,0,0,"20151112","","A","","","","",""
I'd like to find a way to add wildcards in the places noted below as WILDCARD:
"EEID","SUPLIFE","Voluntary Life Insurance","WILDCARD","WILDCARD",WILDCARD,WILDCARD,WILDCARD,WILDCARD,WILDCARD,WILDCARD,"20151112","","A","","","","",""
The final output would then look like the following after the find/replace with wildcards to add VLIFE:
"EEID","SUPLIFE","Voluntary Life Insurance","500000.00","500000.00",0,276,10.62.0,0,0,"20151112","","A","VLIFE","","","",""
Thanks,
Brandon
Tested in Notepad++ and appears to work:
("EEID","SUPLIFE","Voluntary Life Insurance",([^,]+,){8}"","A",)("")(.*)
and replace pattern:
\1"VLIFE"\4
Regex101 example

Replacing chemform in wiki - regexp

could you please give me some advice, I'm replacing the <chemform> code from my wiki which is not used any more... The strings are usually simple like these:
<chemform>CH3COO-</chemform>
<chemform>Ba2+</chemform>
<chemform>H2CO3</chemform>
I need them to be replaced by these:
CH<sub>3</sub>COO<sup>-</sup>
Ba<sub>2</sub><sup>+</sup>
H<sub>2</sub>CO<sub>3</sub>
So far I came up with this regexp for the RegExr tool:
match: <chemform\b[^>]*>(\D*?)([0-9]*)(\D*?)(\D*?)([0-9]*)(\D*?)([-+]*?)</chemform>
replace: $1<sub>$2</sub>$3$4<sub>$5</sub>$6<sup>$7</sup>
I know the code is horrible, but so far it's been working for me except for the fact it's getting me empty strings like <sub></sub>:
<sub></sub>CH<sub>3</sub>COO<sup>-</sup>
<sub></sub>Ba<sub>2</sub><sup>+</sup>
H<sub>2</sub>CO<sub>3</sub><sup></sup>
How can I get rid of these without doing second replace search? Thanks a lot!
You could use Notepad++, which is able to proceed to conditional replacements (you can have details in that previous post from Wiktor Stribiżew).
Use the following patterns:
match: ([A-Za-z]+(?=[-+\d]))(?<sub>\d+)?(?<sup>[-+])?(?=[-+\w]*</chemform>)
replace: $1(?{sub}<sub>$+{sub}</sub>)(?{sup}<sup>$+{sup}</sup>)
Given your input sample, I get:
<chemform>CH<sub>3</sub>COO<sup>-</sup></chemform>
<chemform>Ba<sub>2</sub><sup>+</sup></chemform>
<chemform>H<sub>2</sub>CO<sub>3</sub></chemform>

a simple (i think) REGEX needed for Textmate

Can someone please advise how to do this search and replace in textmate. I think I need a REGEX (but i know very little about REGEXes!)
i want to change all these bullet images to GIFs...
bullet-1.png
becomes
bullet-1.gif
and I want where the number is to be a wildcard
The regular expression:
bullet-(\d+).png
The replacement:
bullet-$1.gif