Match only first occurrence of digit

Marko

After few hours of disappointed searching I can't figure this out.

I am piping to grep input, what I want to get is first occurrence of any digit.

Example:

nmcli --version
nmcli tool, version 1.1.93

Pipe to grep with regex

nmcli --version |grep -o '[[:digit:]]'

Output:

1
1
9
3

What I want:

1

Yeah there is a way to do that with another pipe, but is there "pure" single regex to do that?

Cyrus

With GNU grep:

nmcli --version | grep -Po ' \K[[:digit:]]'

Output:

1

See: Support of \K in regex

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Match only the first occurrence of a phrase

From Dev

Match only the first occurrence of a phrase

From Dev

regex replace only the first occurrence of every match

From Dev

How to match only first occurrence of space at line

From Dev

regex replace only the first occurrence of every match

From Dev

How can I get sed to only match to the first occurrence of a character?

From Dev

Regex to match only the first occurrence of four numbers in a line

From Dev

append a line after pattern match ONLY after first occurrence

From Dev

Regex to match only the first occurrence on the string in notepad++

From Dev

how to insert file contents on match using sed - first occurrence only

From Dev

Java regex skip some characters match only one occurrence of digit, with intermittent periods

From Dev

Replace only first occurrence

From Dev

regex to match up to first occurrence of

From Dev

Match only if not preceded or followed by a digit

From Dev

awk - split only by first occurrence

From Dev

QString replace only first occurrence

From Dev

Php token on first occurrence only

From Dev

Regex matching first occurrence only?

From Dev

replace only first occurrence of a word

From Dev

Sed : replace words only with first occurrence of string in the line not till last match

From Dev

Search first occurrence and print until next delimiter, but match whole word only

From Dev

Matching the first occurrence of underscore followed by a digit and replacing set of matches in html

From Dev

How to preg_match first occurrence in a string

From Dev

Regex match first occurrence before and closest to string

From Dev

RegEx match first occurrence before keyword

From Dev

regex match first occurrence of a single character

From Dev

sed - trying to replace first occurrence after a match

From Dev

PHP Regex Match from Start to First Occurrence

From Dev

Regex to match first occurrence of a string is matching the last

Related Related

  1. 1

    Match only the first occurrence of a phrase

  2. 2

    Match only the first occurrence of a phrase

  3. 3

    regex replace only the first occurrence of every match

  4. 4

    How to match only first occurrence of space at line

  5. 5

    regex replace only the first occurrence of every match

  6. 6

    How can I get sed to only match to the first occurrence of a character?

  7. 7

    Regex to match only the first occurrence of four numbers in a line

  8. 8

    append a line after pattern match ONLY after first occurrence

  9. 9

    Regex to match only the first occurrence on the string in notepad++

  10. 10

    how to insert file contents on match using sed - first occurrence only

  11. 11

    Java regex skip some characters match only one occurrence of digit, with intermittent periods

  12. 12

    Replace only first occurrence

  13. 13

    regex to match up to first occurrence of

  14. 14

    Match only if not preceded or followed by a digit

  15. 15

    awk - split only by first occurrence

  16. 16

    QString replace only first occurrence

  17. 17

    Php token on first occurrence only

  18. 18

    Regex matching first occurrence only?

  19. 19

    replace only first occurrence of a word

  20. 20

    Sed : replace words only with first occurrence of string in the line not till last match

  21. 21

    Search first occurrence and print until next delimiter, but match whole word only

  22. 22

    Matching the first occurrence of underscore followed by a digit and replacing set of matches in html

  23. 23

    How to preg_match first occurrence in a string

  24. 24

    Regex match first occurrence before and closest to string

  25. 25

    RegEx match first occurrence before keyword

  26. 26

    regex match first occurrence of a single character

  27. 27

    sed - trying to replace first occurrence after a match

  28. 28

    PHP Regex Match from Start to First Occurrence

  29. 29

    Regex to match first occurrence of a string is matching the last

HotTag

Archive