Check occurrence in REGEX for php files

Asked

Viewed 32 times

1

In php, I have to open a system file and check if after occurrence 10 of a char in the case ";" what is the content right after it.

example: TPD;62384;P;;;;N;62308;N;;C;N;N;;F;02 what would be the regex for this purpose?

1 answer

1


You can use this regex

(.*?;){10}(.*?);

Explanation
(.*?;) - This sequence captures everything before the character ; so Lazy.
{10} - This is a quantifier, here it expresses that the previous sequence must be captured 10 times.
(.*?); - Then after the tenth repetition of the sequence .*?; the second catch group is placed to give match content after the tenth occurrence of ;.

Note: It is valid to remember that the content you want to capture is in the second capture group of this regex, not in the first.

You can see how this regex works here.

  • So if I’m in the 1000, I have to do 1000 times that?

  • @ALE_ROM you would have to modify the quantifier from 10 to 1000

  • Dough man, thanks for the help

Browser other questions tagged

You are not signed in. Login or sign up in order to post.