How to make a regex that accepts one line but not two?

1

I get lost while doing any complex regex.

I use the following code in java:

Pattern pattern = Pattern.compile("tentativas de regex aki");
Matcher matcher = pattern.matcher(conteudo);
while(matcher.find()) {
   System.out.println(matcher.group());
}

And for the regex, it should do the following search:

[Any Special Character] [free spaces (any quantity) that contains a maximum of 1 line] [letters] ['no letter' (the first q appears ends)]

Legend:

  • line - \ n
  • space - ''
  • free space - I just thought that way because I would like it to end the regex only after the first letter came, but, do not accept it if two lines or more came!

    Can someone convert this to regex?

        
    asked by anonymous 16.02.2016 / 01:17

    1 answer

    3

    I do not know if I understood correctly, but:

    ([^\n]*\n)([a-zA-Z]+)([^a-zA-Z])
    
    • ([^\n]*\n) takes anything until it finds a \n
    • ([a-zA-Z]+) a-zA-Z any quantity should have at least 1
    • ([^a-zA-Z]) anything other than a-zA-Z, once.

    NOTE: \n = line break.

        
    16.02.2016 / 03:10