Click here to Skip to main content
15,891,788 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
The code
C#
string pattern = @"[0-9]*,\V[0-9]";
string input = @"1,560";
foreach (Match m in Regex.Matches(input, pattern))
{    Console.WriteLine("'{0}' found at index {1}.", m.Value, m.Index); }

ends wit Error 'Unbekannte Escape-Zeichenfolge \V.'.


What ist teh problem?

What I have tried:

Where i use <a href="https://regex101.com/">Online regex tester and debugger: PHP, PCRE, Python, Golang and JavaScript</a>[<a href="https://regex101.com/" target="_blank" title="New Window">^</a>] 
than runns this without error and match 1.
Posted
Updated 6-Aug-20 3:05am
Comments
Sandeep Mewara 6-Aug-20 8:41am    
Not too sure of what you are trying as the details are in non-english. Posting based on what seems to be the possible cause.

"\V" is not a valid Regular expression sequence, but "\v" is. Try this:
C#
string pattern = @"[0-9]*,\v[0-9]";
But that won't match your test data at all - because it contains no vertical whitespace, and will only pick up the first digit after the comma.

Get a copy of Expresso[^] - it's free, and it examines and generates Regular expressions.

Quote:
My goal is to remove the last zeros from the string.
1,56700 --> 1,567

Try this:
[0-9]*,[0-9]+?(?=0*$)
It treats the last zeros (if any) and the end of string as a not-included suffix, but allows zeros in the "body":
1506700 -> 1,5067
 
Share this answer
 
v2
Comments
Sandeep Mewara 6-Aug-20 11:03am    
My 5!
There is no capital V as a sequence. It's small 'v'.

Here, a list of valid escape sequences: Regular Expression Escape Sequence[^]

@"/[0-9]*,\v[0-9]"; // should not throw an error
 
Share this answer
 
Comments
otsch 6-Aug-20 9:05am    
Yes, where i use 'v' throw not an error.
But i hve not match.
My goal is to remove the last zeros from the string.
1,56700 --> 1,567
Sandeep Mewara 6-Aug-20 10:29am    
I was not sure of your requirement. Above solves the error you faced.

To remove the last zeros from the string, try:
(?=.*?)(.*?[1-9])(?!.*?\.)(?=0*$)|^.*$

There would be more ways (probably simpler way - you need to try) to do it though.
OriginalGriff 6-Aug-20 10:35am    
I posted a simpler way before I saw yours - sorry!
Sandeep Mewara 6-Aug-20 11:01am    
No worries. :)
OriginalGriff 6-Aug-20 10:36am    
Updated my solution.
In PHP regular expressions, \V means "anything except vertical whitespace".

That token doesn't exist in the .NET Regular Expression language:
Regular Expression Language - Quick Reference | Microsoft Docs[^]

Instead, you would need to negate the \v token:
C#
string pattern = @"[0-9]*,[^\v][0-9]";
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900