How can i write regex to get all words in string. Example

- Travel in Egipt (travel, in, Egipt)
- london cca 300 EUR (x cca y eur, where x is londox and y is 300)

What regex must look like for this two examples? I need two regex but i do not know how to write them.

Thx

it sounds impossible to me regarding your example, if you are sure of the order that the words occur in those sentences, then you can, split the sentences into array of strings and then use array indexing to grab the item.

so you advise me to use split not regex for this?

Waht about "new york cca 300eur"
New your has two words for city and if i use split i can not get new york but just new in first array filed.

So it is impossible to get with regex "x cca y eur" The pattern is "cca eur"

i think what you expect from a regular expression is way to much, you can not solve your problem by regular expressions because you dont have a specific pattern to match.

hmm i just want with regex that regex will check string for example "Greece for cca 300 eur" or "Italy for cca 500 eur" if match with "x for cca y eur" that i will know if this is my pattern that i am looking for.

I think that this can be done with regex?

Read this article and find out what regex can and can not do.

i look MSDNAA site for regex not Wiki and i think that regex can chek patterns if match or not...

This is regex for php. It works in php but in C# not. Can someone please convert ti it aspx?

$string = "London for cca 400 eur";

if(preg_match("/(.+) for cca ([\d.,]+) eur/i",$string,$match)) echo $match[1]." - ".$match[2]."€";
else echo 'Not the same';

Ok my C# code

string strRegex = @"/(.+) for cca ([\d.,]+) eur/i";
            Regex test= new Regex(strRegex);
            String s = "London for cca 400 eur";

            Match m = lala.Match(s);

            if (m.Success)
            {
                 Console.WriteLine(s + " is valid");
            }
            else
            {
                Console.WriteLine(s + " is not valid");
            }
            Console.WriteLine();

always show is not valid...
In php this regex works...

you are the most stubborn poster :D

i hope this is not true

being a stubborn programmer is a good thing.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.