Php Regex: How to make a submatch optional if is at the end of subject

Hybred

New Member
\[code\]$text = 'something here *ls67 another thing'; // match$text2 = 'something here *ls67. another thing'; // match$text3 = 'something here another thing *ls67.'; // match$text3 = 'something here another thing *ls67'; // doesn't match (and i need to match this)$pattern = '|^(.*)?(\*[0-9a-zA-Z_-]{3,15})([^0-9a-zA-Z_-])+(.*)?$|i';\[/code\]I've tried this pattern but it generates an error:\[code\]$pattern = '|^(.*)?(\*[0-9a-zA-Z_-]{3,15})([^0-9a-zA-Z_-]|$)+(.*)?$|i'; // Unknown modifier '$'// and$pattern = '|^(.*)?(\*[0-9a-zA-Z_-]{3,15})(([^0-9a-zA-Z_-])+|$)(.*)?$|i'; // same error\[/code\]
 
Back
Top