regex - Grep regular expression for 4 digits among character string of variable length -


I need some methods to find words and any combination of digits but exactly 4 marks only , and at least one character

Example:

  a1a1a1a1 // match 1234 // no match (no letter) a1a1a1a1a1 // no match AB2b2 / no match CD12 / match Match 9999 / Match 1 AB 26A 9 // Match 1B1C1 // // Match Match 12345 / No Match 24 / No Match A2B2C2D2 / Match AB11CD22D3D3 / [
itemprop = "text">

To match a digit in GP [0-9] ] You can use. To match any number, you can use [^ 0- 9] because it can not be any number, or any character, so you add "*" (any number preceding it). So what do you want logically

(nothing a digit or nothing) * (no single digit) (nothing a digit or nothing) *. ...

Unless you have 4 "no single digits" group i.e. i.e. [^ 0- 9] * [0-9] ...

I am meeting with long patterns, especially with the long string of special characters, it is best to raise slowly, you are sure you understand what is going on. For example,

  # This will expose your matches, and it will otherwise make grep = 'grep --color = auto' echo 'a1b2' easier to understand. Grep '[0-9]'  

will show you how this match is going on. Once you understand each part you can expand the pattern.


Comments

Popular posts from this blog

Is there an open source WebSockets (JavaScript) XMPP library? -

java - Is there an object like a "Set" that can contain only unique string values, but also contain a count on the number of occurrences of the string value? -

iphone - How do I make a UIPickerView in a UIActionSheet -