user1228907 user1228907 - 1 year ago 57
PHP Question

PHP preg_replace match numbers following a special character

I'm creating a comment board feature that allows users to reference post-ID's, which will be auto-configured by regex to hyperlink to the relevant post.

Posts references are formatted as the following, using the double-arrow ASCII symbol:


6 numbers maximum can follow the double-arrow in order for the reference to be hyperlinked, so
would not hyperlink, but
, etc would.

How would I go about doing this with regex?

Answer Source

Match the special character followed by 1-6 digits and then followed by a word boundary, so it won't match if it's concatenated with any other string.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download