webdevask.com

Menu

  • Home
  • New
  • Add question

php - Capture separately if there is a comma, capture it as a whole if there is not RegEx

View Original

Closed. This question needs details or clarity. It is not currently accepting answers.

Answer

Solution:

Try this regex,

It is case-insensitive, captures Lastname and Firstname seperately if there's a comma between them,

And captures together if there's no comma

([^,\r\n]+)

Output:

image

You can also try them without using any classes, like [^,\r\n]+

Edit: After some discussions in the comments, i've came up with an another Regex, which avoids reading Name: in the string

((?(?<=Name:)| )[^,\r\n]+)

Output:

image2

tell me if its okay for you...

Source

See also:

  • php สร้าง Google ชีตจากบัญชีบริการ

  • php - Laravel 8.0 Installation Failed

  • javascript - How to include HTML data (tags) as value in "arrayToDataTable" of Google Pie Chart?

  • how to Grouping array in php

  • php - vender folder from my laravel project has more 1k error

© 2021
E-mail: contact@webdevask.com
Back to top