I am trying to split a string into sentences with preg_split, but I would like it to not split initials.
Examples:
Mark H. Doolittle is my name. What is yours. ( I don't want it to split the middle initial, but want to split after 'name')
The company is is called H.R. Block. They are a good company. ( I don't want it to split after 'H', 'R')
Here is the code i have, but it causes a split at every period. can someone help me out, im not good a regex yet.
[PHP]$sentences = preg_split ("/[.?!]+/", $data);[/PHP]
3 5194
That is quite difficult to distinguish. Example: what would such an expresssion do with sentences like - That is for you and I. But not for him.
No expression can distinguish between you "Mark H. Doolittle" and "and I. But".
Ronald
Atli 5,058
Recognized Expert Expert
I cant see a simple solution to this either.
For this to work, the code would have to be able to distinguish between the end of line periods and those used for other purposes, such as names and numbers.
Your code would have to be able to recognize all possible uses of a period and decide whether or not it really is the end of a line.
Honestly, I doubt that is "doable"... (I would say possible, but nothing is "impossible " ;P)
That is quite difficult to distinguish. Example: what would such an expresssion do with sentences like - That is for you and I. But not for him.
No expression can distinguish between you "Mark H. Doolittle" and "and I. But".
Ronald
I understand that there will definitely be some problems, but most likely the only one letter word that would fall at the end of a sentence would be "I" like in your example: - That is for you and I. But not for him.
I'll figure that out later, but for now is there anyway you could show me how i would do a preg_split that would:
not split any "." that came after a single character instance of 'a-zA-Z', but then split the rest of the "." that did not follow that rule
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Alexander Ross |
last post by:
is there an easy way to split a string on SPACE except if that SPACE is
within QUOTES?
i.e. - $str = red green blue yellow "blue green" returns
?
|
by: Justin L. Kennedy |
last post by:
I am looking for a function that takes in a string and splits it using a
list of other strings (delimiters) and can return the delimiters as well
as the extra parts of the string. I was trying the split with a regex
built up of the delimiters separated by "|", but it doesn't return the
delimiters which I need.
The goal is an algorithm that can take a string containing html code using
<ul>, <ol>, and <li> and turn it into a formated...
|
by: afrinspray |
last post by:
I'm writing a function that parses a nested list string that might look
like this:
( "HELLO WORLD!" 1231231 awesome ( 1 2 ) )
I wrote the logic already and it starts by splitting the string by the
space character (or tab or newline).
ex... $tklist = preg_split("/\s|\n|\t/", $str);
This works except in the string case, where "HELLO WORLD!" should not
be two parts. How do I split by spaces but keep phrases inside quotes
|
by: none |
last post by:
Hello:
Using PHP 4.3.11
The line: $strDate = preg_split('//', $my_date);
works to break apart a date in the form mm/dd/yyyy or mm.dd.yyyy or
mm-dd-yyyy
but the line: $strDate = preg_split('//', $my_date);
doesn't work.
|
by: Chris Thompson |
last post by:
Hi All,
Trying to split a string where there are occurances of a space, a comma, a
newline (char 10), or a return (char 13) using the preg_split function, but
not sure how to write the regular expression for this...
Anyone any idea please?
Thanks,
Chris.
| |
by: Ben |
last post by:
Hi,
To simplify this request, we supposed this following sql script:
"insert into table a values ('me;you','then'); insert into table a
values ('you;me','so');"
Note the semi-colon ( ; ) in strings for the first field in both
queries.
|
by: Vince Morgan |
last post by:
My problem has a simple solution. However I just can't find it. I cannot
remember which 'split()' type function allows you to keep the delimiter in
place within the final array.
I've tried searching the documentation without success.
TIA
Vince
|
by: Geoff Berrow |
last post by:
Does anyone know what regular expression I would use to split text into
an array, assuming the text can be separated by any non alphanumeric
character?
e.g
$string ="cat,dog fish, mouse -elephant/tiger";
would give
|
by: John |
last post by:
Hi
I have written a function to split a string into sub strings of a given
fixed max length. This is useful for example in breaking a long message into
multiple strings of up to 160 characters to be sent as individual SMS.
I am posting the function here in case its useful for someone.
Regards
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |