|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
How to resolve this problem with Regular Expression?
Hi there, i need a Regular expression for finding a line with this:
Example PHP Code:
and cahnge it to : PHP Code:
Notice that i need the same word inside the quotes, y only need the regex for adding the escape slashes to the line in front of the quotes....... NOTE: I dont know why is not shown the first slash??? so thats a forum error or protection!..----- Thanks! Last edited by Next_Gate : May 2nd, 2003 at 11:17 AM. |
|
#2
|
|||
|
|||
|
Are you trying to do slash quoting of quotation marks.
If this is in PHP: Maybe you could have a look at the string addslashes (string str) function You could also just use str_replace(search, replace, subject) If I'm missing the idea, just tell me. Here is the regex: for the matching: ="(.*?)" for the replacement =/"\1/" Last edited by sadrok : May 3rd, 2003 at 01:36 PM. |
|
#3
|
|||
|
|||
|
im not trying to do it within the php program or script, i want to do it using a text editor. Im using Textpad that support RegEx...
|
|
#4
|
|||
|
|||
|
can you not use back references like \1 ?
try the find bit like this: Code:
[^=]\" and the replace bit: Code:
\\\" Code:
[^=]\" Code:
=\"(.*?)\" Code:
[^=]\" Last edited by balance : May 3rd, 2003 at 06:35 PM. |
|
#5
|
||||
|
||||
|
With the note you added to your first post, do you just want all quotes escaped? That doesn't need a regex, just search for " and replace with \" If you don't want the quote following the = to be escaped, but all others should be, we'd need to know more about what kind of regex your editor supports. I use UltraEdit and it had it own odd version of regular expressions that I had to learn to use, but in recent versions, unix-style support has been added, which I'm much more familliar with.
In perl, I'd use something like this: s/(?<!=)"/\\"/ Perl supports a variety of zero width assertions (don't know how many are standard supported), positive and negative, look-ahead and look-behind. This one uses negative look-behind. (?<!pattern) matches so long as pattern does not match what comes immediately before it, in this case, an equals sign. Since it's zero-width, it doesn't actually consume the character in the match, and there's no need for explicit back references.
__________________
Andrew - Perl (and VB.NET) Monkey Never underestimate the bandwidth of a hatchback full of tapes. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Software Design > How to resolve this problem with Regular Expression? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|