简体   繁体   中英

regex match only specific file lines

I have a file containing lines like:

13  
13-55  
some text 11  

I want to create a regex to match only first to type of lines, but not the last one. Reges created by me is [0-9\\-]+

You have to specify that you are testing from the beggining to the end of the string:

Try with following regex:

^[0-9-]+$

Try using anchors ( ^ and $ to denote beginning and end of string respectively) and use the multiline option (this one depends on the language/engine/environment of the regex).

^[0-9-]+$

Note, you can drop the backslash for the - if it's at the beginning or end of a character class.

如果要匹配以数字开头的行。

^[0-9-]+$

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