Regular expression – how to search for words or plural versions [copy]

See the English answer> Regex search and replace with optional plural 4
I am trying to make a simple regular expression, what I want to do is to match the strange part of a word, Whether it has an s ending or not. So, if I have the following

test
tests

Edit: further example , I need this possibly many words and not just those two

movie
movies
page
pages
time< br />times

For all of these I need to get the word without ending, but I can’t find a regular expression, it will always grab the first place without ending s and Applicable to two situations.

I have tried the following methods:

([a-zA-Z]+)([s]{ 0,})-This returns the full word as the first match in both cases
([a-zA-Z]+?)([s]{0,})-This returns 3 different matching groups for both words
([a-zA-Z]+)([s]?)-This returns the full word as the first match in both cases
([a-zA-Z]+) (s)-This works for tests but doesn't match test at all
([a-zA-Z]+)(s)?-This returns the full word as the first match in both cases

I have been using http://gskinner.com/RegExr/ to try out different regular expressions.

Edit: This is a sublime text fragment, for those who don’t know The sublime text snippet is a shortcut so that I can type in the name of my database and click “run snippet”, it Will turn it into something like:

$movies= $this->ci->db->get_where("movies", "");
if ($movies->num_rows()) {
foreach ($movies->result() AS $movie) {

}
}

I only need to turn “movie” into “movie” and automatically insert it into the foreach loop.

This means I can’t just search and replace text, I only need to consider 60-70 Words (it only refers to my own list, not every word in English).

Thank you!
– Tim

Okay, I found a solution:

< /p>

([a-zA-Z]+?)(s|)

Work as needed, then you can simply use the An unusable version that matches as a word.

Thank you @Jahroy for helping me find it. I added this as an answer for future surfers, they just want a solution, but please check Jahroy’s Comment for more in-depth information.

See the answer in English> Regex search and replace with optional plural 4
I am trying to make a simple regular expression, What I want to do is to match the singular part of a word, whether it has an s ending or not. So, if I have the following

test
tests

Edit: For further example, I need this may be many words instead of just those two

movie
movies
page
pages
time
times

For all of these I need to get the word without ending, but I can’t find a regular expression, it always Will grab the first s without ending and apply to two situations.

I have tried the following methods:

([a-zA -Z]+)([s]{0,})-This returns the full word as the first match in both cases
([a-zA-Z]+?)([s] {0,})-This returns 3 different matching groups for both words
([a-zA-Z]+)([s]?)-This returns the full word as the first match in both cases
([a-zA-Z]+)(s)-This works for tests but d oesn't match test at all
([a-zA-Z]+)(s)?-This returns the full word as the first match in both cases

I have been Use http://gskinner.com/RegExr/ to try out different regular expressions.

Edit: This is a sublime text fragment, a shortcut for those who don’t know the sublime text fragment, so I can type in the name of my database and click “Run Fragment”, it will turn it into something like:

$movies= $this->ci-> db->get_where("movies", "");
if ($movies->num_rows()) {
foreach ($movies->result() AS $movie) {

}
}

I just need to turn “movie” into “movie” and automatically insert it into the foreach loop.

This means I You can’t just search and replace text, I only need to consider 60-70 words (it is only for my own table, not every word in English).

Thank you!
– Tim

Ok, I found a solution:

([a-zA-Z]+?)(s|)

Work as needed, then you can simply use the first match as the unusable version of the word.< /p>

Thank you @Jahroy for helping me find it. I added this as an answer for future surfers, they just want a solution, but please check Jahroy’s comment for more in-depth information.

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 5443 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.