PHP/REGEX: Bullets if Line Starts with Dash

Posted on 2012-09-16
Last Modified: 2012-09-16
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.
Question by:hankknight
    LVL 74

    Expert Comment

    by:käµfm³d 👽

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

    Open in new window

    LVL 74

    Accepted Solution


    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


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Suggested Solutions

    Whatever be the reason, if you are working on web development side,  you will need day-today validation codes like email validation, date validation , IP address validation, phone validation on any of the edit page or say at the time of registration…
    Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
    The viewer will learn how to count occurrences of each item in an array.
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now