[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 684
  • Last Modified:

PHP/REGEX: Bullets if Line Starts with Dash

Using PHP and REGEX, how can I automatically convert dashes at the beginning of each line into bullets, providing there is exactly one space after the dash and the proceeding charactor is NOT a lowercase letter?


- Hello World
should become:
• Hello World

- 123 Testing
should become:
• 123 Testing

- this is a test
should not be changed.

Hello - World
should not be changed.
0
hankknight
Asked:
hankknight
  • 2
1 Solution
 
käµfm³d 👽Commented:
Try:

$result = preg_replace('/^- (?![a-z])/', "• ", $input);

Open in new window

0
 
käµfm³d 👽Commented:
P.S.

You may need to turn on multi-line mode depending on the source data:

$result = preg_replace('/^- (?![a-z])/m', "• ", $input);

Open in new window

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now