Thread: Simple question

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

    Join Date
    Jul 2012
    Location
    Brussels
    Posts
    1
    Rep Power
    0

    Simple question: remove character


    Hi,

    I am very new with RegEx.

    I have a variable containing 3 datas (Salary, Name, Job) separated by 3 separators: { }

    The variable contains: 45000{Barak Obama}President

    We user the regular expresion below to retrieve the first data:
    \s*(((?!|{).)+)\s*{
    The result is: 45000{

    Problem: we want to remove the separators "" and "{" to only have 45000
    How is it possible with regular expressions ?

    Thanks !
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2011
    Posts
    29
    Rep Power
    0
    You should extract the first subexpression by using \1 or $1 in the replacement text. Depending on the programming language that you use, it will be $1 (Perl) or \1 (Python).

    You can also use lookbehind/lookahead:

    Code:
    (?<=)\d+(?=\s*{)
    If the salary can contain only digits, you should use \d+

    (((?!|{).)+) can be replaced with shorter and more effective [^{]+

    Comments on this post

    • ManiacDan agrees
  4. #3
  5. No Profile Picture
    Banned
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Posts
    14
    Rep Power
    0
    You should get the very first subexpression by utilizing \1 or perhaps $1 inside substitute wording. With respect to the coding words which you work with, it'll be $1 (Perl) or perhaps \1 (Python).

    Comments on this post

    • Scorpions4ever disagrees : If you're going to plagiarise a post, make sure it isn't the post above your reply.

IMN logo majestic logo threadwatch logo seochat tools logo