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

    Join Date
    Oct 2013
    Posts
    4
    Rep Power
    0

    Need help 4 a regex command


    Hello!

    Can somebody help me with the following regex command?
    I have: "Spa Spaten Franziskaner-Brau GmbH Spa"

    I have to Replace the first "Spa" and the Last "Spa" to an empty string without change the "Spa" in the Word "Spaten".

    I think i Need something like this:
    \sSpa$ and/or Spa\s

    Thanks 4 Help!!
  2. #2
  3. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,920
    Rep Power
    1045
    Hi,

    this is pretty vague. You didn't even say what programming language you're using, so I'll choose one: Ruby.

    I guess you want an uppercase "Spa" surrounded by non-letters or the beginning/end of the string.

    ruby Code:
    /(?<=\A|\p{^L})Spa(?=\z|\p{^L})/
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    4
    Rep Power
    0
    Hello!

    I use C#

    I want to ignore uppercase and remove "Spa" surrounded by non-letters or the beginning/end of the string.

    So just remove if it is a complete word.

    Thanks 4 Help!
    myGil
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    4
    Rep Power
    0
    Hmmm ...

    I think this can work: \bSpa\b
  8. #5
  9. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,920
    Rep Power
    1045
    Originally Posted by mygil
    I want to ignore uppercase
    Ignore case? Then why do you keep writing "Spa"?



    Originally Posted by mygil
    I think this can work: \bSpa\b
    If you consider strings like "Spa_foo" or "Spa512" as "words" (i. e., "Spa" should not be replaced), then yes. Otherwise, this is wrong.
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    4
    Rep Power
    0
    ?

    When i ignore Case then i can write:
    "Spa" "spa" "SPA" "sPa" "spA" "SpA"

    At Moment i use:
    Regex.Replace(szTextFile, @"(?i)\bspa\b", "");
    and it works fine 4 me!
    Thanks 4 your help!

IMN logo majestic logo threadwatch logo seochat tools logo