Regex Programming
 
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 - MoreRegex Programming

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 February 4th, 2009, 12:55 AM
ryel01 ryel01 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2005
Posts: 227 ryel01 User rank is Sergeant (500 - 2000 Reputation Level)ryel01 User rank is Sergeant (500 - 2000 Reputation Level)ryel01 User rank is Sergeant (500 - 2000 Reputation Level)ryel01 User rank is Sergeant (500 - 2000 Reputation Level)ryel01 User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 1 Day 15 h 4 m 42 sec
Reputation Power: 15
Search and replace wildcard* for use in REGEXP

hi

Here are two examples of a string...

1. "looking for bec* in here"
2. "find thi*"

What I want to do is find and replace all * with X within the string, so it would need to match * followed by a space, or at the $ end of the string.

The X I'm replacing it with needs to be used inside a REGEXP, and it needs to match any character following up to the next space.

So using my REGEXP... "looking for bec* in here" would be translated to find...

looking for become in here
looking for bec23423 in here
looking for bec in here

but NOT...

looking for become random in here
looking for bec 23423 in here

The same results would be applicable for example 2 above.

Can anyone help with this one?

Thanks.
Regan

Reply With Quote
  #2  
Old February 4th, 2009, 03:10 AM
prometheuzz prometheuzz is offline
User 165270
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2005
Posts: 497 prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level) 
Time spent in forums: 5 Days 10 h 14 m 35 sec
Reputation Power: 936
Quote:
Originally Posted by ryel01
...

What I want to do is find and replace all * with X within the string, so it would need to match * followed by a space, or at the $ end of the string.


I don't really understand the examples you posted, but the requirements above can be translated into the following regex:

Code:
regex       : \*(?=\s|$)       
replacement : X


Note that \s matches white space characters, tabs, new line characters etc.

Reply With Quote
  #3  
Old February 4th, 2009, 04:11 AM
ryel01 ryel01 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2005
Posts: 227 ryel01 User rank is Sergeant (500 - 2000 Reputation Level)ryel01 User rank is Sergeant (500 - 2000 Reputation Level)ryel01 User rank is Sergeant (500 - 2000 Reputation Level)ryel01 User rank is Sergeant (500 - 2000 Reputation Level)ryel01 User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 1 Day 15 h 4 m 42 sec
Reputation Power: 15
Quote:
Originally Posted by prometheuzz
Code:
regex       : \*(?=\s|$)       
replacement : X



Thanks prometheuzz. Sorry if my explanation wasn't too clear.

Using your regex to replace the *, what would "X" need to be to be to be used in the following REGEXP code to find any matches...

Code:
table_column REGEXP '(^|[[:<:]])this is my str* to search($|[[:>:]])'


regan

Reply With Quote
  #4  
Old February 4th, 2009, 10:05 AM
prometheuzz prometheuzz is offline
User 165270
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2005
Posts: 497 prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level) 
Time spent in forums: 5 Days 10 h 14 m 35 sec
Reputation Power: 936
It still is not clear to me what it is you're trying to do.
Can you give a couple (more than one!!!) example strings and for each string clearly indicate what parts you want to find/match or what string you want t get after replacing a certain pattern?

Reply With Quote
  #5  
Old February 4th, 2009, 01:34 PM
ryel01 ryel01 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2005
Posts: 227 ryel01 User rank is Sergeant (500 - 2000 Reputation Level)ryel01 User rank is Sergeant (500 - 2000 Reputation Level)ryel01 User rank is Sergeant (500 - 2000 Reputation Level)ryel01 User rank is Sergeant (500 - 2000 Reputation Level)ryel01 User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 1 Day 15 h 4 m 42 sec
Reputation Power: 15
Quote:
Originally Posted by prometheuzz
It still is not clear to me what it is you're trying to do.
Can you give a couple (more than one!!!) example strings and for each string clearly indicate what parts you want to find/match or what string you want t get after replacing a certain pattern?



Hi prometheuzz

table_column contains a long string of text. I want to search that long string of text and find...

"the car is an au*"

which will find the following results (assuming they're in the string)...

"the car is an automatic"
"the car is an audi"
"the car is an authentic"

Or if I search for... "hello Im g* thanks very much" it will find....

"hello Im good thanks very much"
"hello Im great thanks very much"
"hello Im giddyup thanks very much"


Using the last example this is along the lines of what I'm looking for...

Code:
table_column REGEXP '(^|[[:<:]])hello Im g[^\s]* thanks very much'


Regan

Last edited by ryel01 : February 4th, 2009 at 01:41 PM.

Reply With Quote
  #6  
Old February 4th, 2009, 01:41 PM
prometheuzz prometheuzz is offline
User 165270
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2005
Posts: 497 prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level) 
Time spent in forums: 5 Days 10 h 14 m 35 sec
Reputation Power: 936
Quote:
Originally Posted by ryel01
...

Using the last example this is along the lines of what I'm looking for...

Code:
table_column REGEXP '(^|[[:<:]])hello Im g[^\s]+thanks very much'


Regan


Hi,

I presume that "table_column REGEXP '(^|[[:<:]])hello Im g[^\s]+thanks very much'" doesn't work?

What regex-flavour are you using? How does your input come to you?

But I guess you're doing some regex matching with a database regex-flavour. If this is the case, I cannot help you further since I'm not familiar with it. Sorry!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreRegex Programming > Search and replace wildcard* for use in REGEXP

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