简体   繁体   中英

regex in multiline

I am having trouble writing a regex for the last "}" in the last line in a file. for example:

if this is the file:

    /*
           blas
     */

    import bla;


public class bla {
...

    public void bla (blas){
    ...
    }

...
} //this is the "}"

Can anyone help? it's preferable if you have an idea that doesn't rely on indentation of lack of additional comments in the end (I think it's fair to assume that even if there are comments in the end then they don't contain "}"), but right now I'm prepared to take anything.

The best I could do was: ^}$ but that relies on proper indentation.

Thanks a lot in advance.

No need for multi-line modifiers, just use this }(?=[^}]*$)
This would find the last } in the file.

If you want to force a find only on the last line it's (?m)^.*(}).*\\z

or, if the last visible line it's (?m)^.*(}).*\\s*\\z

Simple as halwa!

use this:

}.*?$

Example here: https://regex101.com/r/oM3tW3/1

If you want to return the match, use:

(}).*?$

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM