Got more questions? Find advice on: ASP | SQL | XML | Windows
in Search
Welcome to RegexAdvice Sign in | Join | Help

Capture the first word in a string?

Last post 03-23-2010, 5:32 PM by jemo. 2 replies.
Sort Posts: Previous Next
  •  03-05-2010, 6:24 AM 60401

    Capture the first word in a string?

    Helllo, 

    This is for either java, js, or a posix not sure where I will end up developing it.

    I am currently testing js with the current regex: ´/(\b[A-Z]{4}\b)/´ the string is as follows: "EIDW 050900Z 26006KT 240V310 0300 R16/0450N R28/0600V0800U R10/0600V0800U FZFG SCT001 BKN003 M00/M00 Q1033 BECMG 1200"

    Currently I want to extract only the first word with 4 capital characters, when I test I get hits on "EIDW" <--- this is the text I need, but also "FZFG".  What am I missing?

    I appreciate your help.

    Regards,

     

    Jemo 

  •  03-06-2010, 3:48 PM 60422 in reply to 60401

    Re: Capture the first word in a string?

    (by reading the positing guidelines, you would know that it is extremely complex to help when one example is provided)

     

    Anchor the first word to the beginning of the buffer

    ´/^[A-Z]{4}\b/´

    This will not select anything else that the first word at the very beginning of the buffer, if it exists

    If there are spaces, tabs, leading \n\r, any combination of the above, between the beginning of the buffer and the word you want to select, use \s

    If there are spaces, tabs, leading \n\r, any combination of the above, between the beginning of the buffer and the word you want to select, use \s

    ´/^\s*[A-Z]{4}\b/´

    Does it solve your problem ?

  •  03-23-2010, 5:32 PM 62116 in reply to 60422

    Re: Capture the first word in a string?

    Peadarin, thank you. you solved my issues with your guidance. 

     

    I will keep my post with language related questions. :( 

    PD: Email subscription did not work for me. 

View as RSS news feed in XML