Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Oct 2008
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question find and replace 20 number in word.

    hi all,
    i need to replace number 20 in following word with space.
    please help me to write regular exprssion for it.

    only2020%20left20on20/,

    i have written the ~s/20/ /g; it works but it replaced second 20 number also in this word
    output of this :
    only % left on /,
    i want output: only 20% left on /,
    please help me to write regular expresion for this.
    Thanks in advance.

  • #2
    Senior Coder shyam's Avatar
    Join Date
    Jul 2005
    Posts
    1,563
    Thanks
    2
    Thanked 163 Times in 160 Posts
    ~s/%20/ /g;?
    You never have to change anything you got up in the middle of the night to write. -- Saul Bellow

  • #3
    Senior Coder
    Join Date
    Mar 2006
    Posts
    1,274
    Thanks
    2
    Thanked 39 Times in 38 Posts
    You can use a negated lookahead assertion:

    Code:
    $_ = 'only2020%20left20on20/,';
    s/20(?!%)/ /g;
    print;
    means to replace 20 with a space if it is not proceeded by the % symbol
    Last edited by KevinADC; 05-30-2009 at 01:20 AM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •