I writing preg_match_all
which test for match on string. It is working for for normal string and numeric values but when I pass GUID it fail.
/{([\w\-_]*[\w]{1})\(?([\w,]*)?\)?([+,])?([a-zA-Z]*)?\(?([\w\/]*)?([\-,])?([\w\/]*)?\)?}/
Data which pass is
{abc_test(1))}
What I want to be pass is
{abc_test(1))}
and {abc_test(2dc7ba10-fe29-4de6-9282-a4ebc5eee87d))}
{abc_test(2dc7ba10-fe29-4de6-9282-a4ebc5eee87d))}
will always have GUID
.
My Answer:
To match a GUID in your regular expression, you can add the pattern for a GUID within the parentheses. Here is an updated version of your regular expression that should match both normal strings and GUIDs:
php
/{([\w\-_]*[\w]{1})\(?([\w,]*)?\)?([+,])?([a-zA-Z]*)?\(?([\w\/-]*)?([\-,])?([\w\/-]*)?\)?}/
In this updated regular expression, `([\w\/-]*)` is used to match the GUID pattern. This pattern will match alphanumeric characters, dashes, and slashes, which are commonly found in GUIDs.
Now, your regular expression should be able to match strings like `{abc_test(1))}` and `{abc_test(2dc7ba10-fe29-4de6-9282-a4ebc5eee87d))}`.
Rate this post
4 of 5 based on 7577 votesComments