Thread: Beginner, help

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

    Join Date
    Aug 2003
    Posts
    95
    Rep Power
    12

    Question Beginner, help


    I have a list of job titles (all that are title case) and I wish to use regular expression to check if the title contains the word Pa. If so then I wish to change it to uppercase (PA), however there are other job titles such as Accounts Payable which I would like to stay as they are as opposed to being changed to Accounts PAyable.
    So my regular expression would be find any references of Pa and make uppercase unless proceeded by another letter.

    As I am new to Regex can anybody help?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2007
    Posts
    765
    Rep Power
    929
    You can use word boundary assertions:
    Code:
    /foo\b/ # Matches 'foo' only at the end of a word
    Or negative look-aheads:
    Code:
    /bar(?!\w)/ # Matches 'bar' only if \w does not match after
    Check your regex engine's documentation for which are supported and the exact syntax.
    sub{*{$::{$_}}{CODE}==$_[0]&& print for(%:: )}->(\&Meh);
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    95
    Rep Power
    12
    Thanks OmegaZero, but I could not get that to pick up any references so after abit of research (based on what you had supplied) the following seems to match my needs:
    \b(Pa)\b

IMN logo majestic logo threadwatch logo seochat tools logo