need help creating the correct regex pattern
Posted: Wed Apr 08, 2009 2:38 pm
I am trying to write a function that will take a string and return a substring. Best to show by example:
I want to return the first word or words in the string that are all capital letters. For example, if the string is:
This sentence HAS THREE WORDS in a row that are all caps.
I want the expression to return "HAS THREE WORDS"
If the string is
This sentence HAS THREE WORDS in a row that are all caps and ANOTHER all caps word
it should find only "HAS THREE WORDS" and ignore any other words or letters that are all
caps.
I've been trying this pattern which doesn't work:
[\bA-Z]+^[\bA-Z]
Please help!
Thanks
I want to return the first word or words in the string that are all capital letters. For example, if the string is:
This sentence HAS THREE WORDS in a row that are all caps.
I want the expression to return "HAS THREE WORDS"
If the string is
This sentence HAS THREE WORDS in a row that are all caps and ANOTHER all caps word
it should find only "HAS THREE WORDS" and ignore any other words or letters that are all
caps.
I've been trying this pattern which doesn't work:
[\bA-Z]+^[\bA-Z]
Please help!
Thanks