0

I've got a string like this:

family="ABeeZee;100regular" decoration="" style="normal" txtalign="txt-left" size="14px" line="22px" padding="0px" bold="" uppercase="" color=""" 

And I want just to get the value/string inside family:

 ABeeZee;100regular

I know that I need to use regex but I still don't understand how to write the pattern...

I tried this without success:

$mystring = 'family="ABeeZee;100regular" decoration="" style="normal" txtalign="txt-left" size="14px" line="22px" padding="0px" bold="" uppercase="" color=""" '
$pattern  = '/(family)="([\'"])?((?(1).+?|[^\s>]+))(?(1)\1)"/is';
$string   = preg_replace($pattern, "", $mystring);
0

1 Answer 1

2

Use preg_match() instead of preg_replace() to grab the value.

You only have a single pattern so you don't need to use a conditional regex here.

preg_match('/family="([^"]+)"/', $mystring, $match);
echo $match[1]; //=> "ABeeZee;100regular"
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot! Do you know a website/tuto where I can correctly learn regex because I'm very bored to don't understand...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.