Regular Expression at the end of the string not matching

Mukil Deepthi

I am trying to extract values in groups from a string. My regex is

string str = @"DEMOV 1'07"" MOT Lifestyle 503080 Pure Rain Nozzle Feb 13 472000";

const string type = @"(?<type>\w+)";
const string minutes = @"((?<minutes>\d+)\')?";
const string seconds = @"((?<seconds>\d+)\"")?";
const string body = @"(?<body>.+)";
const string id = @"(?<id>\s\d{6})?";

var pattern1 = String.Format(@"^{0}(?:\s\w+)?\s({1}{2}|{1}|{2})\s?{3}{4}$", type, minutes, seconds, body, id);
var m1 = Regex.Match(str, pattern1);

I am getting the match, but the the group is not getting the last 5 digit.

Can anyone tell me what i am doing wrong here?

Please find below the output i am getting.

enter image description here

Jcl

Use the non-greedy version (use .+? for body), and don't add the spaces to the id group:

const string body = @"(?<body>.+?)";
const string id = @"\s(?<id>\d{6})?";

In action: https://dotnetfiddle.net/L1yL3C

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Regular Expression: matching plural cases at end of string

From Dev

Matching regular expression at the end of the string with Python 2.7.13

From Dev

Regular expression not matching string

From Dev

Regular expression matching with string

From Dev

Regular expression for matching string

From Dev

regular expression not matching for string

From Dev

Regular expression matching from the end

From Dev

Regular Expression not matching a string as expected

From Dev

returning string matching regular expression

From Dev

Why is the regular expression not matching the string?

From Dev

Regular expression - matching inside a string

From Dev

returning string matching regular expression

From Dev

Regular expression - matching inside a string

From Dev

regular expression evaluation in string matching

From Dev

Trying to understand python regular expression end of string matching with \Z, \b, $ vs just ending the expression

From Dev

Part of regular expression should not be matching . or , in the end

From Dev

regular expression find end of string

From Dev

JavaScript regular expression for matching start and end of string and priting the whole string within matched value?

From Dev

Regular expression for matching single occurrence of ' (single quote) coming only between alphabets not on start or end of the string

From Dev

Matching multiple words within a string with regular expression

From Dev

String pattern matching with regular expression in java

From Dev

Matching word using Regular Expression in a string

From Dev

Regular expression not matching specific string and strict test

From Dev

Regular Expression for Matching String not beginning or ending with alphabet

From Dev

Matching double space in regular expression string with BootstrapValidator

From Dev

Regular expression for multiple matching in a hierarchical string

From Dev

Matching a string with regular expression returns null

From Dev

Regular Expression Help - Difficulty Matching String

From Dev

Replace string by matching using regular expression python

Related Related

  1. 1

    Regular Expression: matching plural cases at end of string

  2. 2

    Matching regular expression at the end of the string with Python 2.7.13

  3. 3

    Regular expression not matching string

  4. 4

    Regular expression matching with string

  5. 5

    Regular expression for matching string

  6. 6

    regular expression not matching for string

  7. 7

    Regular expression matching from the end

  8. 8

    Regular Expression not matching a string as expected

  9. 9

    returning string matching regular expression

  10. 10

    Why is the regular expression not matching the string?

  11. 11

    Regular expression - matching inside a string

  12. 12

    returning string matching regular expression

  13. 13

    Regular expression - matching inside a string

  14. 14

    regular expression evaluation in string matching

  15. 15

    Trying to understand python regular expression end of string matching with \Z, \b, $ vs just ending the expression

  16. 16

    Part of regular expression should not be matching . or , in the end

  17. 17

    regular expression find end of string

  18. 18

    JavaScript regular expression for matching start and end of string and priting the whole string within matched value?

  19. 19

    Regular expression for matching single occurrence of ' (single quote) coming only between alphabets not on start or end of the string

  20. 20

    Matching multiple words within a string with regular expression

  21. 21

    String pattern matching with regular expression in java

  22. 22

    Matching word using Regular Expression in a string

  23. 23

    Regular expression not matching specific string and strict test

  24. 24

    Regular Expression for Matching String not beginning or ending with alphabet

  25. 25

    Matching double space in regular expression string with BootstrapValidator

  26. 26

    Regular expression for multiple matching in a hierarchical string

  27. 27

    Matching a string with regular expression returns null

  28. 28

    Regular Expression Help - Difficulty Matching String

  29. 29

    Replace string by matching using regular expression python

HotTag

Archive