Regular expression issues in .net 6 value converter
文章推薦指數: 80 %
There are some missing parts in your regular expression, for example it doesn't have the curly braces { and } escaped, since curly braces ...
Home
Public
Questions
Tags
Users
Companies
Collectives
ExploreCollectives
Teams
StackOverflowforTeams
–Startcollaboratingandsharingorganizationalknowledge.
CreateafreeTeam
WhyTeams?
Teams
CreatefreeTeam
Collectives™onStackOverflow
Findcentralized,trustedcontentandcollaboratearoundthetechnologiesyouusemost.
Learnmore
Teams
Q&Aforwork
Connectandshareknowledgewithinasinglelocationthatisstructuredandeasytosearch.
Learnmore
Regularexpressionissuesin.net6valueconverter
AskQuestion
Asked
3monthsago
Modified
3monthsago
Viewed
97times
0
Iamtryingtolearnsome.net6andc#andIamstrugglingwithregularexpressionsalot.MorespecificalywithAvaloniainWindowsifthatisrelevant.
Iamtryingtodoasmallappwith2textboxes.Iwritetextononeandgetthetext"filtered"intheotheroneusingavalueconverter.
Iwouldliketofiltermathexpressionstotrytosolvethemlateron.Somethingsimple,kindofawayofwritingtextmathandgettingresultsrealtime.
Ihavebeentryingforseveralweekstofigurethisregularexpressiononmyownwithnosuccesswhatsoever.
Iwouldliketoreplaceinmystring"_Expression{BLABLA}"for"BLABLA".FortestingmyexpressionsIhavebeencheckinginhttp://regexstorm.net/andhttps://regex101.com/andaccordingtothemmymatchesshouldbecorrect(unlessImisunderstoodtheresults).ButtheresultsinmylittleappareextremelyoddtomeandIfinallydecidedtoaskforhelp.
Hereismycode:
privatestaticstring?FilterStr(objectvalue)
{
if(valueisstringstr)
{
stringpattern=@"\b_Expression{(.+?)\w*}";
Regexrgx=new(pattern);
foreach(Matchmatchinrgx.Matches(str))
{
stringaux="";
aux=match.Value;
aux=Regex.Replace(aux,@"_Expression{","");
aux=Regex.Replace(aux,@"[\}]","");
str=Regex.Replace(str,match.Value,aux);
}
returnnewstring(str);
}
returnnull;
}
Thentheresultsforsomesampleinputsare:
Input:
Sometext
_Expression{x}
_Expression{1}
_Expression{4}
_Expression{4.5}_Expression{4+4}
_Expression{4-4}_Expression{4*x}
_Expression{x/x}
_Expression{x^4}
_Expression{sin(x)}
Output:
Sometext
x
1{1}
1{4}
1{4.5}1{4+4}
1{4-4}1{4*x}
1{x/x}
1{x^4}
1{sin(x)}
or
Input:
Sometext
_Expression{x}
_Expression{4}
_Expression{4.5}_Expression{4+4}
_Expression{4-4}_Expression{4*x}
_Expression{x/x}
_Expression{x^4}
_Expression{sin(x)}
Output:
Sometext
x
_Expression{4}
4.5_Expression{4+4}
4-4_Expression{4*x}
x/x
_Expression{x^4}
_Expression{sin(x)}
Itfeelsveryconfusingtomethisbehaviour.Ican'tseewhy"(.+?)"doesnotworkwithsomeofthemanditdoeswithothers...OrmaybeIhaven'tdefinedsomethingproperlyormyReplaceiswrong?Ican'tseeit...
Thanksalotforthetime!:)
c#regex.net-6.0ivalueconverter
Share
Follow
askedMar15at10:47
JorgeLLJorgeLL
311bronzebadge
Addacomment
|
1Answer
1
Sortedby:
Resettodefault
Highestscore(default)
Trending(recentvotescountmore)
Datemodified(newestfirst)
Datecreated(oldestfirst)
0
Therearesomemissingpartsinyourregularexpression,forexampleitdoesn'thavethecurlybraces{and}escaped,sincecurlybraceshaveaspecialmeaninginaregularexpression;theyareusedasquantifiers.
Usetheonebelow.
Forextractingthemathexpressionbetweenthecurlybraces,itusesanamedcapturinggroupwithnamemathExpression.
_Expression\{(?
延伸文章資訊
- 1How Do I Test a Regular Expression? - RegexLand
- 2Regex Tester and generator - Beautify Converters
Regex Tester and generator helps you to test your Regular Expression and generate regex code for ...
- 3Regular Expression Analyzer
- 4Regular expression issues in .net 6 value converter
There are some missing parts in your regular expression, for example it doesn't have the curly br...
- 5Free Online Regular Expression Tester - FreeFormatter.com
This free regular expression tester lets you test your regular expressions against any entry of y...