Regex command cannot get value help

Hi,
I have problem with capturing info from below input which is when the input have a “-” symbol it can captured but when there is no “-” regex cant get the value

Regex command used

(Plot ([\d]+) [-|=] Plot\s*(\d+))\s?=.+?(\d+)| (Block [\d]+)\s(Plot ([\d]+) [=-] Plot\s*(\d+))\s?=.+?(\d+)

Input format

(Plot 526 Plot 549) = 24 units Block 16 (Plot 707 - Plot 762) = 56 units
(Plot 526 - Plot 549) = 24 units Block 16 (Plot 707 - Plot 762) = 56 units

expected captured value is
a=526
b=549
c=24
d=Block 16
e=707
f=762
g=56

by regex command above I only manage to get the output if there is “-” format for (Plot 526 - Plot 549) but if the input no “-” symbol => (Plot 526 Plot 549) I can’t get the value

Need help on this. Thank you

Try this

(Plot (\d+)\s?[-]?\s?Plot\s*(\d+))\s?=\s?(\d+)\s?units|Block\s(\d+)\s(Plot\s(\d+)\s?[-]?\s?Plot\s*(\d+))\s?=\s?(\d+)\s?units

@Abang_Jamuri_Abang_Shoker

Hi,

Can you try the following sample?

mc = System.Text.RegularExpressions.Regex.Matches(strText,"Plot\s*(?<FIRSTVALUE>\d+)\s*Plot\s*(?<SECONDVALUE>\d+)\D+(?<THIRDVALUE>\d+).*?Block\s*(?<FORTHVALUE>\d+).*?Plot\s*(?<FIFTHVALUE>\d+).*?Plot\s*(?<SIXTHVALUE>\d+).*?(?<SEVENTHVALUE>\d+)")

Sample
Sample20241129-3.zip (2.6 KB)

Regards,

Hi Sharazkm32

cant get the output

Hi Yoichi,

if possible can you provide command in normal regex

Do you mean you need regex pattern without named group? if so, how about the following?

Plot\s*(\d+)\s*Plot\s*(\d+)\D+(\d+).*?Block\s*(\d+).*?Plot\s*(\d+).*?Plot\s*(\d+).*?(\d+)

Regards,

Yes,

manage to get the value if there is no “-” but when the input have “-” symbol no data

Hi,

Can you share your input string as text as the following (indent by 4 spaces)?

input String

Regards,

sample Input

(Plot 526 Plot 549) = 24 units Block 16 (Plot 707 - Plot 762) = 56 units
(Plot 520 - Plot 529) = 9 units Block 24 (Plot 707 - Plot 762) = 56 units

I need to get selected value from both input.

Hi,

Thanks. Can you try the following pattern?

Plot\s*(\d+).*?Plot\s*(\d+)\D+(\d+).*?Block\s*(\d+).*?Plot\s*(\d+).*?Plot\s*(\d+).*?(\d+)

Regards,

1 Like

Manage to get the output

Thank you very much Yoichi

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.