Home > Mobile >  Regex to get specific word that is followed by text after it (in the SAME LINE) - JAVA
Regex to get specific word that is followed by text after it (in the SAME LINE) - JAVA

Time:02-17

I'm searching a Regular expression, that matches a specific word followed by any other words in the same line in multiline text, For example :

I have a small code to test on it:

in this code I want to matches all words that start with "@" and there is a words after it in the same line (the result that I want from this code, is to get the second @Override because there are some words and letters after it in the same line).

editText.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override       public void onTextChanged(CharSequence s, int start, int before, int count) {
                
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });

picture of example show what i want

enter image description here

CodePudding user response:

How about the word @Override with a non-space character after it? Note that this would perhaps incorrectly grab comments if you have them on that line, but anyways this is a starting place. Please update the question with more examples if you want a more refined match.

  • enter image description here

  • Related