Example document like this:
“Chess helps us overcome difficulties and sufferings,” said Unnikrishnan, taking my queen. “On a chess board you are fighting. as we are also fighting the hardships in our daily life.” he said.
I want to get output like this:
Array
(
[0] =>"Chess helps us overcome difficulties and sufferings," said Unnikrishnan, taking my queen.
[1] =>"On a chess board you are fighting. as we are also fighting the hardships in our daily life," he said.
)
My code still explode by dots.
function sample($string)
{
$data=array();
$break=explode(".", $string);
array_push($data, $break);
print_r($data);
}
I'm still confused to split two delimiter about double quote and dot. because inside double quote there is a sentence that contain dot delimiter.
You can also get a double-quoted text value by using the split () method: const textWithQuote = 'One of my favorite quotes is "First we make our habits, then our habits make us". This quote is sometimes attributed to John Dryden, or other authors.' console.log( textWithQuote.split('"')[1])
Notice that if there is a double quote in the middle of a word it will be split (a"ctuall"y would be a, ctuall, y in the final result). If the last double quote is unmatch it won't split from its position to the end of the string.
Learn how to extract text between double quotes from a string with JavaScript. Let’s say you want to get some quoted text from a text block. Quotes are usually wrapped by double quotes ( " " ). No problem, you can use JavaScript’s match () method and some RegEx magic.
Add double quote on different words in notepad++. 1 use FIND: (?-s)^.+$ => REPLACE: "$0", my example will become*: 2 use FIND: (?-s)^.*$ => REPLACE: "$0", my example will become*:
A perfect example for (*SKIP)(*FAIL)
:
“[^“”]+”(*SKIP)(*FAIL)|\.\s*
# looks for strings in double quotes
# throws them away
# matches a dot literally, followed by whitespaces eventually
PHP
:
$regex = '~“[^“”]+”(*SKIP)(*FAIL)|\.\s*~';
$parts = preg_split($regex, $your_string_here);
This yields
Array
(
[0] => “Chess helps us overcome difficulties and sufferings,” said Unnikrishnan, taking my queen
[1] => “On a chess board you are fighting. as we are also fighting the hardships in our daily life.”
)
See a demo on regex101.com as well as a demo on ideone.com.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With