any number before quote (VB NET)

gwendaal

Newcomer
Joined
Dec 15, 2004
Messages
1
I am looking for a regex ..
I mut find all what is nymeric before quotes in a string

Monitor,IBM ThinkPad 17" TFT LCD (93516843009)
I must get >>> 17

DELL [15"]

I must get >>> 15

thank you for helping
 
Regex search string plus Visual Studio .NET 2003 Solution

gwendaal said:
I am looking for a regex ..
I mut find all what is nymeric before quotes in a string

Monitor,IBM ThinkPad 17" TFT LCD (93516843009)
I must get >>> 17

DELL [15"]

I must get >>> 15

thank you for helping

gwendaal,

One regular expression search string you can use is:

[^0-9][0-9]+["]

This says find a non-digit followed by one or more digits followed by a double quote. If the string to be searched is:

lasfjdlasfkj 9479287 alsdfjlsajf923749247" alsdjflsfj 92723974 alsfjflj

The result will be:

f923749247"

You will have to strip off the leading and trailing character to get the number.

I have attached a zip file that contains an entire Visual Studio .NET 2003 solution that gives you a window with text boxes to input a string to be searched, a regular expression string and a search result box. You can enter any string you like to be searched and use the above search string to test your desired result and also use it to play with regular expressions in general.

I hope that this helps! :)
 

Attachments

Last edited by a moderator:
My solution was in C#, but you can convert it to VB

Sorry! :( My solution I provided is in C#, but you should be able to convert it to VB. The main thing is the class usages. Holler if you need help. :)
 
The exact result you want

You can replace my button click routine with the following code (that you can convert to VB :( ) and it will return exactly what you are looking for, just the number right before the double quote.

Code:
		private void button_Test_Click(object sender, System.EventArgs e)
		{
			string tmpstr1 = Regex.Match(this.textBox_String_to_Test.Text, this.textBox_Regular_Expression.Text,RegexOptions.IgnoreCase).ToString();
			string tmpstr2 = tmpstr1.Substring(1,tmpstr1.Length-2);
			this.textBox_Result_will_show_here.Text = tmpstr2;
		}
 
Back
Top