How to construct a string based on regex and related parameters in PHP?

Posted by user198729 on Stack Overflow See other posts from Stack Overflow or by user198729
Published on 2010-03-10T17:09:48Z Indexed on 2010/03/21 8:31 UTC
Read the original article Hit count: 252

Filed under:
|
(?P<id>\d*)(/(?P<title>.*))?

Most of the time,we use regex to match something,but how to generate the matching string if we have id and title already?

Example,if id=4 and title='hello world',the result should be:

4/hello world

But if we only have id=4,it should be:

4

Because as the regex indicates,title is optional.

Two answers both misunderstood...

There is no preg_match yet

© Stack Overflow or respective owner

Related posts about php

Related posts about regex