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

    Join Date
    Dec 2013
    Posts
    6
    Rep Power
    0

    Simple reg ex - help need baaadly


    I am doing some apex code in Salesforce (pretty much java), I am looking for a reg expression which will extract the following reference number in the below html text string…ie. P24-101419480

    Please help me with a regular expression to extract the string "P24-101419480" from the attached html string...

    "<br />
    <strong>Message:</strong> Please send me more information about web reference P24-101419480 in Berea, Johannesburg. dale test
    </p>
    <p>"
  2. #2
  3. No Profile Picture
    Php Freelance Web development
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 1999
    Location
    chennai , tamil nadu , India
    Posts
    60
    Rep Power
    16
    Originally Posted by DalePurdon
    ...............................................
    Please help me with a regular expression to extract the string "P24-101419480" from the attached html string...
    ............................."
    Code:
    ([A-Z0-9]{3}\-[0-9]{9})
    could be a start.
    Chris, Developer, Chrisranjana.com
    Chennai, Tamil Nadu, India.
    Php Programmers
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2013
    Posts
    6
    Rep Power
    0
    Thanks you very much. i managed to get that one sorted, maybe you can help with this? Been battling for ages....

    I am trying to get the value 'S848270' out of the following text string...


    "Tel: 0712222222
    Email:xxxxxxxxxx
    Your property: BEREA, 8 Tudhope Heights, Corner Primrose & Tudhope
    Street (S848270)
    Message: Hi Obotseng Phokompe, I found this listing on Private Property
    and would like more information."


    I am trying to use the following reg expression. 'S[0-9][0-9][0-9][0-9][0-9][0-9]'


    When i test it in a 3rd party reg expression tool it finds the value ok. But in my apex code it is not finding a match for some reason? Do i need to try put other characters into the reg expression because i am using apex? I have no idea why its not working if it appears to work in the 3rd party reg expression matching tool.

    the way my code is....(myPlainText is already set to the long string above)...if you can come up with a better reg expression... that actually works, that would be great (Apex is the same as java)

    static pattern PATTERN_PRIVATEPROPERTY_ENQUIRY_REF = pattern.compile('S[0-9][0-9][0-9][0-9][0-9][0-9]');


    mr = PATTERN_PRIVATEPROPERTY_ENQUIRY_REF.matcher(myPlainText);
    if (mr.find()) {
    ref = mr.group(1).deleteWhitespace();
    system.debug('privateproperty reference found:'+ref);

    }

    else

    {

    system.debug('privateproperty reference NOT found:'+ref);

    }
  6. #4
  7. No Profile Picture
    Php Freelance Web development
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 1999
    Location
    chennai , tamil nadu , India
    Posts
    60
    Rep Power
    16
    Originally Posted by DalePurdon
    Thanks you very much. i managed to get that one sorted
    Can you let me know what exact regex pattern you are using for the last one ?
    Chris, Developer, Chrisranjana.com
    Chennai, Tamil Nadu, India.
    Php Programmers
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2013
    Posts
    6
    Rep Power
    0
    im trying to use this one..... S[0-9][0-9][0-9][0-9][0-9][0-9]

    ie.

    static pattern PATTERN_PRIVATEPROPERTY_ENQUIRY_REF = pattern.compile('S[0-9][0-9][0-9][0-9][0-9][0-9]');
  10. #6
  11. Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jan 2004
    Location
    New Springfield, OH
    Posts
    1,222
    Rep Power
    1469
    Is there any reason you're not using (S\d{6}) or (S[0-9]{6})?

    That being said, I see no reason why your pattern won't work. Are you getting any errors or just no match?
    Last edited by Nilpo; December 13th, 2013 at 04:04 PM.
    Don't like me? Click it.

    Scripting problems? Windows questions? Ask the Windows Guru!

    Stay up to date with all of my latest content. Follow me on Twitter!

    Help us help you! Post your exact error message with these easy tips!
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2013
    Posts
    6
    Rep Power
    0
    I did try (S\d{6}) or (S[0-9]{6})?

    maybe its not wokring because i am accessing the wrong group?

    I many groups would the above match bring back? should i rather be using... ref = mr.group(0).deleteWhitespace();

    Im not 100% sure on how groups work. I do nkow that if you have multiple sections in brackets then it will results in numerous groups coming back?
  14. #8
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2013
    Posts
    6
    Rep Power
    0
    also...what i did notice was....it didnt seem to return a match when i tried to match against this string...

    "

    "Tel: 0712222222
    Email:xxxxxxxxxx
    Your property: BEREA, 8 Tudhope Heights, Corner Primrose & Tudhope
    Street (S848270)
    Message: Hi Obotseng Phokompe, I found this listing on Private Property
    and would like more information."

    how ever it does seem to return a match where there are no line feeds. eg. i do get a match against a sinle line string like this...

    "Street (S848270)"

    would line feeds make a difference?
  16. #9
  17. Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jan 2004
    Location
    New Springfield, OH
    Posts
    1,222
    Rep Power
    1469
    Line feeds will make a difference if you are using ^ and $. It shouldn't matter since you aren't, but you could try adding the multiline modifier.

    Code:
    pattern.compile('S[0-9][0-9][0-9][0-9][0-9][0-9]', pattern.MULTILINE)
    Don't like me? Click it.

    Scripting problems? Windows questions? Ask the Windows Guru!

    Stay up to date with all of my latest content. Follow me on Twitter!

    Help us help you! Post your exact error message with these easy tips!
  18. #10
  19. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2013
    Posts
    6
    Rep Power
    0
    Thanks all sorted!

IMN logo majestic logo threadwatch logo seochat tools logo