简体   繁体   中英

Using grep to find all occurrences of the following pattern

I'm trying to find all occurrences of pattern that looks like this:

/*  93 */
/*  94 */
/*     */
/*  96 */
/*  99 */
/*     */
/* 101 */

I've failed miserably producing the correct regex. Desired goal would be to find all that match all the above

Expressions I've treid

(\/)(\*)(\s)(\s)(\d)(\d)(\s)(\*)(\/)

It matches the first occurance of /* somenumber */ but no subsequent matches. It also wont match times when there are three digit numbers and also ones with no numbers

This is what you are looking for

 \/\*\s*\d+\s*\*\/

No need of grouping each and every part in regex unless you want to store it in a group

\\d+ matches 1 to many digits..

\\s* matches 0 to many spaces..

Try the following:

\\/\\*[^\\*]*\\*\\/

http://www.rubular.com/r/HMDl9QH3uq

Try '/* *[0-9 ][0-9 ][0-9 ] **/'

This expression will select just your rows and will not select

/* xxx */

/* c */

/* 1014 */

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