Re: Tricky regex question



On Jan 31, 11:29 am, Juan Singh <j...@xxxxxxxxxxxxx> wrote:
Daniel.

PERFECT! Thank you. This is exactly what I was looking for.

Juan.

Daniel Pitts wrote:
On Jan 31, 10:54 am, Juan Singh <j...@xxxxxxxxxxxxx> wrote:
Hi,

I need to split words from a sentence that are more than 2 letters. An
example sentence is:

This is "very" 'tricky'. I won't be able see it.

I came up with the following regex, but it breaks the word [won't] and I
only get the part that is before the single quote.

\b[a-zA-Z]{2,}+\b

My objective is to extract the following words from the example sentence
above.

This, very, tricky, won't, able

Thanks.
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Test {
public static void main(String[] args) {
Pattern longword = Pattern.compile("\\w+('?\\w){2,}");
String input = "This is \"very\" 'tricky'. I won't be able see
it.";
Matcher matcher = longword.matcher(input);
while (matcher.find()) {
System.out.println(matcher.group());
}
}
}


As Andrew Thompson says:
"Future lack of top-posting will be thanks enough".

On this group, we reply AFTER the quote or mixed-in with the quote!

.



Relevant Pages

  • Re: Problem with single quote character
    ... Building dynamic SQL sometimes results in statements like ... because the quote in renders the sql ... run it through REPLACE first to change the single quote to two single ... About the only other character I can think of off the top of my head ...
    (comp.databases.oracle.misc)
  • RE: Password
    ... "Dave Hawks" wrote: ... There should be as a double quote, single quote, and space before the AND as ... Make sure that after PWORD = there is a space, single quote, and double quote. ... USERID = '" ...
    (microsoft.public.access.formscoding)
  • Re: OT: Steve Carroll begs to go to jail
    ... And yet you cannot quote a single quote of mine where I have *ever* done so. ... of harassing her any time you'd like, Snit. ... "based on sexual or lustful feelings" for you. ...
    (comp.sys.mac.advocacy)
  • RE: Password
    ... There should be as a double quote, single quote, and space before the AND as ... Make sure that after PWORD = there is a space, single quote, and double quote. ... USERID = '" ... "Dave Hawks" wrote: ...
    (microsoft.public.access.formscoding)
  • RE: Password
    ... Note there are some single quote ... There should be as a double quote, single quote, and space before the AND as ... USERID = '" ... "Dave Hawks" wrote: ...
    (microsoft.public.access.formscoding)