#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2005
    Posts
    227
    Rep Power
    16

    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
  2. #2
  3. No Profile Picture
    User 165270
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2005
    Posts
    497
    Rep Power
    937
    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.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2005
    Posts
    227
    Rep Power
    16
    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
  6. #4
  7. No Profile Picture
    User 165270
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2005
    Posts
    497
    Rep Power
    937
    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?
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2005
    Posts
    227
    Rep Power
    16
    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.
  10. #6
  11. No Profile Picture
    User 165270
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2005
    Posts
    497
    Rep Power
    937
    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!

IMN logo majestic logo threadwatch logo seochat tools logo