how can I join two regex into one? - asp.net

I have two regex that I need to join into one as I am using the RegularExpressionAttribute in ASP.NET and it does not allow multiple instances.
How can I join the following two regex into one?
.*?#(?!.*?\.\.)[^#]+$
[\x00-\x7F]
the first one checks that there are not 2 consecutive dots in the domain part of an email and the second regex checks that all characters are ascii
I thought it might have been as easy as joining them together like (.*?#(?!.*?\.\.)[^#]+$)([\x00-\x7F]) but this does not work
Here is link to previous post relating to this problem
EDIT: I am decorating an string property of my viewmodel using reglarexpression attribute and this gets rendered into javascript using unobtrusive therefore it has to validate using javascript. I failed to mention this in my initial post

You can use:
^[\x00-\x7F]+?#(?!.*?\.\.)(?=[\x01-\x7F]+$)[^#]+$

You can just use this regex
^[\x00-\x7F-[#]]*?#(?!.*?\.\.)[\x00-\x7F-[#]]+$
Or, if you want to match at least 1 character before #:
^[\x00-\x7F]+#(?!.*?\.\.)[\x00-\x7F-[#]]+$
Mind that [\x00-\x7F] also includes # symbol. In C# regex, we can subtract this from the range using -[#] inside the character class.
And you do not need the anchors since you are using this in a RegularExpressionAttribute, I believe.
Here is a demo on regexstorm.net, remove the second #, and you will have a match.

Related

CSS/RegEx: Select elements where a certain attribute contains only numbers at certain locations

I am currently working on a web app and I need to query a data attribute that repeatedly shows up in a table.
In the table that I declare a data-test-id attribute that I can use later for testing. One example:
<td data-test-id="table-element-1-9:0-cell"> Hello world!<td>
I am querying the data attributes with a css selector for testing. The only thing that changes with each use of the data-test-id attribute are the three numbers which I will replace with X here:
/* css selector */
.select('[data-test-id="table-element-X-X:X-cell"]')
How do I create a regular expression to match all of the other characters is this attribute while ignoring the numbers denoted by X (as in the number denoted by X can be any number from 0-9)?
I tried using the following but it doesn't seem to work:
/\[data-test-id="table-element-[0-9]-[0-9]:[0-9]-cell"\]/g
Well AFAIK there is no regex-matching attribute selector in CSS. You could instead use a broader selector of
[data-test-id^="table-element-"][data-test-id$="-cell"]
This matches all elements with a data-test-id attribute that starts with table-element- and ends in -cell. Of course that might not be specific enough depending on the possible values of that attribute.
If that is the case, you could further filter the elements that are returned by above query using whatever language you call the select function from. For example using the regex you provided above.

Merge aliasByNode and aliasByMetric in Grafana backed by Graphite

I want to label series by hostname + metric name. I know I can use aliasByNode(1) to do first part and aliasByMetric() to do the second. Any ideas how can I merge those two functions in a single metric?
aliasByNode can take multiple arguments.
aliasByNode(apps.fakesite.web_server_01.counters.requests.count, 2,5)
returns web_server_01.count.
The Grafana query editor for Graphite does not support this but if you toggle edit mode then you can edit the raw query. After editing it, you can toggle back.
You may want to check out aliasSub, which allows you to use a regular expression replacement to modify the series name.
In grafana syntax something like aliasSub(([^.]+)([.][^.]+)*[.]([^.]+), \1 \3) should do what you're after.
Something that would solve ALL these problems would just be to have a string with replacement parameters for the metric nodes, like,
aliasByVars("core.app.city.rack.app.instance.thread",
"resource: city-$3,rack-$4")
You could intersperse static text with the values of the metric elements (nodes) all you wanted.
That could replace alias, aliasNode, aliasMetric and 99% of aliasSub with one simple, easy to understand namer.
There would be some aliasSub applications where you used partial node names this could not replace.

CSS/JS - Force a line break at a comma in comma separated list

I have a table cell in which there is list of aircraft registration numbers in the format 'X-XXXX'. The width of the table cell means that the list gets word-wrapped on the hyphen, like so:
G-ABCD,G-
EFGH,G-
IJKL
What I'd like to happen is that the line-break is forced on the comma:
G-ABCD,
G-EFGH,
G-IJKL
However, I cannot insert any special characters. This is because when the form is submitted, the data in the table is submitted as JSON format which is then json_decoded in PHP. Any special characters in the comma separated string then stops the json_decode function from turning it into an array.
So I really need a solution that does not alter the list in anyway? Sounds impossible...
To force a line break, use the <br> tag. If you cannot have it in the HTML markup, add it with JavaScript.
This answers the question asked. The actual problem is probably different. You need to post more code and ask differently to have it solved. What is the context, what are the constraints, and what do you actually want to do? (From the discussion in the comments, it seems that you rather want to prevent line breaks after hyphens than force any breaks.)

Profile View Filters Request URI

I'm trying to "Include Only" about 40 URLs for a specific profile view. I set up three Request URI filters that use "Include Only" and the following regex:
FIRST:
/(subdirectory1|subdirectory2|subdirectory3|subdirectory4)/
(That goes on and on for about 15 subdirectories)
SECOND:
/(subdirectory16|subdirectory17|subdirectory18|subdirectory19)/
(That goes on and on for another 15 subdirectories).
THIRD:
Same thing for whatever remains.
If I only have ONE "Include Only" Request URI filter set up this way, it works. As soon as I add a second filter, it stops tracking everything. Unfortunately, I can't fit all URLs in the one filter.
How can I accomplish this?
Thanks.
The first filter includes the subdirectories 1-15 (if numbered sequentially). Everything else is thrown away. The second filter works on what is left, so from the sequence subdirectory1 to subdirectory15 it only includes those that match the pattern subdirectory16-subdirectory25. Which is none of them.
Filters are applied in the order that they are defined and they are destructive, data that has been deleted in a previous filter is not evaluated in a subsequent filter, hence you see nothing.
An standard include filter does not accept regular expressions (whith the exception of the "|" character). However as far as I know (and according to the documentation) the advanced include filter does.
I'm not great with regular expression, but the following pattern should work or at least be good enough to get you going:
\/subdirectory([1-2][1-9]|[1-9])
The first bit is your directory name. The bit in parenthesis should match the numbers. Specifically:
[1-2][1-9]
should match numbers from 11 to 29 (these are character classes, regex treats numbers as characters not as numbers. So this bit looks for something that starts with 1 or two and is followed by one of the numbers 1,2,3,4,5,6,7,8,9).
Then there is your "or"-sign and a second expression to match numbers that have only one digit.
Change the character classes according to your needs.
You'd have to go from predefined to advanced filter, set "include", use "RequestURI" as filter field and enter the expression. That should work (I admit I haven't tested it).

Filtering a multivalued attribute in StringTemplate

I have a template which uses the same multivalued attribute in various places. I often find myself in a situation where I would like to filter the attribute before a template is applied to the individual values.
I can do this:
<#col:{c|<if(cond)><# c.Attribute2 #><endif>};separator=\",\"#>
but that is not what I want, because then there are separators in the output separating "skipped" entries, like:
2,4,,,6,,4,5,,
I can modify it to
<#col:{c|<if(c.Attribute1)><# c.Attribute2 #>,<endif>};separator=\"\"#>
Which is almost OK, but I get an additional separator after the last number, which sometimes does not matter (usually when the separator is whitespace), but sometimes does:
2,4,6,4,5,
I sometimes end up doing:
<#first(col):{c|<if(cond)><# c.Attribute2 #><endif>};separator=\"\"#>
<#rest(col):{c|<if(cond)>,<# c.Attribute2 #><endif>};separator=\"\"#>
But this approach fails if the first member does not satisfy the condition, then there is an extra separator in the beginning:
,2,4,6,4,5
Can someone give me a better solution?
First, let me point out that I think you are trying to do logic inside your template. Any time you hear things like "filter my list according to some condition based upon the data" it might be time to compute that filtered list in the model and then push it in. That said something like this might work where we filter the list first:
<col:{c | <if(c.cond)>c<endif>}:{c2 | <c2.c.attribute>}>
c2.c accesses the c parameter from the first application
The answer by "The ANTLR Guy" didn't help in my case and I found another workaround. See at Filter out empty strings in ST4

Resources