Regular Expression help

Drakkon

Diamond Member
Aug 14, 2001
8,401
1
0
I am trying to replace text like this:

src="Lecture 1 Something About Something.rm"

to this:

src="Lecture_1_Something_About_Something.rm"

and so I've been trying textpad/notepad++/ultraedit and their regular expression feature but none seem to find based on what appears to me to be the valid regular expression:

\s+(?!([^'\"]*['\"][^'\"]*['\"])*[^'\"]*$)

Any help? ideas? better regular expression?
 

Ken g6

Programming Moderator, Elite Member
Moderator
Dec 11, 1999
16,836
4,815
75
The problem with regular expressions and quotes is finding what is in quotes and what is not. So I'd suggest starting with searching for src=

Ultraedit has weird regular expressions. In ViM, I'd do:

s/\(src *= *"[^ "]*\) /\1_/g

repeatedly, until no more matches are found.
 

troytime

Golden Member
Jan 3, 2006
1,996
1
0
what language are you using for this? regex doesn't seem like the best solution for such a simple string manipulation
 

presidentender

Golden Member
Jan 23, 2008
1,166
0
76
Most languages offer a method to do what you want. In C#, you'd use String.Replace(). In Java, you'd use String.replaceAll(). Technically you use a Regex as an argument in Java, but you can ignore that and just give it a string.
 

Drakkon

Diamond Member
Aug 14, 2001
8,401
1
0
Originally posted by: Ken g6
The problem with regular expressions and quotes is finding what is in quotes and what is not. So I'd suggest starting with searching for src=

Ultraedit has weird regular expressions. In ViM, I'd do:

s/\(src *= *"[^ "]*\) /\1_/g

repeatedly, until no more matches are found.

went with this :) worked out well enough

this wasn't really for any sort of programming project. just needed to edit a ton of XML files fast