pcre - Use Regex to match a set of numbers with variable positioning? -


i'm trying use regex match set of numbers inputed users. want user supply positions , values of 4 digits. idea take info, search list , return 'matching numerical string' of 10 digits if , if digits supplied user in right position. can provide regular expression can use? i'm @ wits end , trying not fired.

quick update example: user inputs ##2#5#8##9

should match

1528578009 8324598769

shouldnt match

4726754839 5023859800

hope helps give idea of im trying do. responses

as far understand input :

p1 v1

p2 v2

p3 v3

p4 v4

where p position , v value of digit. if case, arrange them in increasing order of position assume p1 < p2 < p3 < p4.

now calculate following values :

a1 = p1 - 1

a2 = p2 - p1 - 1

a3 = p3 - p2 - 1

a4 = p4 - p3 - 1

a5 = 10 - p4

now use following regex

[1-9]{a1}v1[0-9]{a2}v2[0-9]{a3}v3[0-9]{a4}v4[0-9]{a5} 

the method based on fact position 1 based. significant digit's position considered 1 , not 0.


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -