agf1997
agf1997

Reputation: 2898

Find a string with regex of unknown length begnning with a specific string

I'm looking find a string of unknown length that beings with abc. The strings end is defined by a space, the end of a line, the end of the file, etc.

The string may contain . characters in the middle.

Examples of what I'm trying to find include:

abc.hello.1.test.a

abc.1test.hello.b.maybe

abc.myTest.1.test.maybe

Characters after the first dot must be present, so the following would not match.

abc.

abc

Upvotes: 1

Views: 2494

Answers (2)

Austin_Anderson
Austin_Anderson

Reputation: 940

If you really just want abc.{any non empty string} its trivial to do ^abc\..+$ which just finds abc. at the beginning, and then matches 1 or more of anything after that

If you want abc.{any string without a space} its similar, ^abc\.[^ ]+$

the ^ and $ are called anchors, and make sure your regex is matching the whole string, instead of say, efg.abc.hij

Upvotes: 1

alpha bravo
alpha bravo

Reputation: 7948

Use this Pattern (abc\.\S+) Demo

(               # Capturing Group (1)
  abc           # "abc"
  \.            # "."
  \S            # <not a whitespace character>
  +             # (one or more)(greedy)
)               # End of Capturing Group (1)

Upvotes: 2

Related Questions