Reputation: 3867
Need regex pattern that text start with"@" and end with " ";
I tried the below pattern
string pattern = "^[@].*?[	]$";
but not working
Upvotes: 0
Views: 2052
Reputation: 4331
This patterns works fine. I have tested it.
string pattern = "#(.*?)9";
See below link to test it online.
https://regex101.com/r/iR6nP6/1
C#
const string str = "dadasd#beetween9ddasdasd";
var match = Regex.Match(str, "#(.*?)9");
Console.WriteLine(match.Groups[1].Value);
Upvotes: 1
Reputation: 8308
You should use \t
to match tab character
You can use special character sequences to put non-printable characters in your regular expression. Use \t to match a tab character (ASCII 0x09)
Try following Regex
^\@.*\t\;$
Upvotes: 0
Reputation: 383
you mean something like:
string pattern = "^@.*?[ ]$"
There are also many fine regex expression helpers on the web. for example https://regex101.com/ It gives a nice explanation of how your text will be handled.
Upvotes: 0
Reputation: 98750
Since 	
is an hex code of tab character, why not just using StartsWith
and EndsWith
methods instead?
if(yourString.StartsWith("@") && yourString.EndsWith("\\t"))
{
// Pass
}
Upvotes: 3
Reputation: 52185
In regex syntaxt, the []
denotes a group of characters of which the engine will attempt to match one of. Thus, [	]
means, match one of an &, #, x or 9 in no particular order.
If you are after order, which seems you are, you will need to remove the []
. Something like so should work: string pattern = "^@.*?	$";
Upvotes: 0