Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Regex for a simple sentence.

Posted on 2007-04-08
4
Medium Priority
?
574 Views
Last Modified: 2012-05-05
Hi,

I've got the sentence "A duck is a bird" and I want to create a regular expression that will detect it from something like this:

^(A )[a-zA-Z0-9]\s\w(is a)[a-zA-Z0-9]$

So that should also work for the sentence "A kitten is a cat".  However, my regex doesn't work, where have I gone wrong?

Cheers,
Col.
0
Comment
Question by:whos_wee_dug
  • 4
4 Comments
 
LVL 85

Expert Comment

by:ozo
ID: 18873461
^(A )[a-zA-Z0-9]\s(is a)[a-zA-Z0-9]$
0
 
LVL 85

Expert Comment

by:ozo
ID: 18873463
^(A )[a-zA-Z0-9]\s(is a)\s[a-zA-Z0-9]$
0
 
LVL 85

Expert Comment

by:ozo
ID: 18873466
Sorry again,
^(A )[a-zA-Z0-9]+\s(is a)\s[a-zA-Z0-9]+$
0
 
LVL 85

Accepted Solution

by:
ozo earned 1000 total points
ID: 18873469
Or just
^A\s+\w+\s+is\s+a\s+\w+$
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As most anyone who uses or has come across them can attest to, regular expressions (regex) are a complicated bit of magic. Packed so succinctly within their cryptic syntax lies a great deal of power. It's not the "take over the world" kind of power,…
We are witnesses that everyone is saying that our children shouldn't "play" with a technology because it is dangerous. This article is going to prove that they are wrong.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Suggested Courses

577 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