Software Design
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreSoftware Design

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old May 2nd, 2003, 10:14 AM
Next_Gate Next_Gate is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Posts: 45 Next_Gate User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 m 36 sec
Reputation Power: 11
How to resolve this problem with Regular Expression?

Hi there, i need a Regular expression for finding a line with this:

Example

PHP Code:
="WhatEverHere" 




and cahnge it to :
PHP Code:
=\\"WhatEverHere\" 



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 10:17 AM.

Reply With Quote
  #2  
Old May 3rd, 2003, 12:31 PM
sadrok sadrok is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Location: South Africa
Posts: 9 sadrok User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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 12:36 PM.

Reply With Quote
  #3  
Old May 3rd, 2003, 04:06 PM
Next_Gate Next_Gate is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Posts: 45 Next_Gate User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 m 36 sec
Reputation Power: 11
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...

Reply With Quote
  #4  
Old May 3rd, 2003, 05:33 PM
balance balance is offline
.
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Posts: 296 balance User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 11
can you not use back references like \1 ?
try the find bit like this:
Code:
[^=]\"

and the replace bit:
Code:
\\\"


Code:
[^=]\"
isn't as good as
Code:
=\"(.*?)\"
because
Code:
[^=]\"
will match any quote that doesn't have an equals infront of it. but if you can't use back refs..

Last edited by balance : May 3rd, 2003 at 05:35 PM.

Reply With Quote
  #5  
Old May 11th, 2003, 11:48 AM
icrf's Avatar
icrf icrf is offline
Perl Monkey
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: May 2003
Location: the far end of town where the Grickle-grass grows
Posts: 1,860 icrf User rank is Second Lieutenant (5000 - 10000 Reputation Level)icrf User rank is Second Lieutenant (5000 - 10000 Reputation Level)icrf User rank is Second Lieutenant (5000 - 10000 Reputation Level)icrf User rank is Second Lieutenant (5000 - 10000 Reputation Level)icrf User rank is Second Lieutenant (5000 - 10000 Reputation Level)icrf User rank is Second Lieutenant (5000 - 10000 Reputation Level)icrf User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 4 Days 11 h 6 m
Reputation Power: 108
Send a message via AIM to icrf
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreSoftware Design > How to resolve this problem with Regular Expression?

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap