Regex for get all html tag without attribute - c

I need to get all HTML tags without attribute from a string. I tried regex: < *([^/][^ ]*).*?> but it still gets HTML tag and attributes.
Can anyone help me find a regex to get this.
Example:
From <html><head></head><body class="body"></body>,
I want to get <html><head></head><body><a></a></body>.
And a Regex to get only html tag
get to html head head body a a body
Thanks all.

While it's not a good idea in general to try to parse HTML with a regular expression, in this case it works.
Try the following replacement
s/<( *\w+)( [^>/]+)?(/?)>/<$1$3>/g
This matches the opening angle bracket, then captures possible white space and any word characters ([A-Za-z0-9_]) following that. Then if there's a white space followed by any characters that are neither a slash nor a closing angle bracket, it matches that. Then it captures an optional slash and the closing angle bracket.
It replaces this with an opening angle bracket, the captured tag, the captured optional slash, and a closing angle bracket.
This assumes there are no opening or closing angle brackets that are not part of a tag.

Related

How to repeat escape character n times in JSX

Say I want to repeat 3 times in span tag and the final result will be <span> </span>
If it is a normal character, I can simply use the code snippet below to archive this requirement
<span>{'x'.repeat(3)}</span>
But now it is an escape character, I don't know how to do that.
Note that you are in Javascript, not in HTML, therefore you can simply:
<span>{'\xa0'.repeat(3)}</span>
However also note that this would be better achieved using :before or :after CSS attributes.

apache camel <simple trim="true" is not working

I'm reading a simple content from a file, say "80631". i validate it against a regex("^\d+$") to check it's just digits. But the validation fails. When i inspect the content read from the file it's something like "80631 ". I tried to trim the whitespace with , but it didn't work. Do we have any other way to trim the whitespace?
<camel:setProperty propertyName="messageId">
<simple trim="true">${body}</simple>
</camel:setProperty>
You should likely show the code to get better help. But <simple trim="true"> ... </simple> is trimming the output of the expression.
Its not for trimming message body.
You need to use message transformation beforehand to trim the message body. Or write a regular expression that ignore leading/ending whitespace.

How can I check and save text from span element

I have been trying to get the text out of a span element without much success.
using the following:
.check(css("span[id='hostName']", "text").saveAs("__HOST")))
but it does not find the text.
this is the html
<span id="hostName" style="padding:0">01</span>
can i do this with css checker or do i have to resort to regex
Direct quote from the Gatling documentation:
css(expression, attribute)
expression can be a plain String, a String using Gatling EL or an Expression[String].
attribute is an optional String.
When filled, check is performed against the attribute value. Otherwise check is performed against the node text content.

Pass regex to variable (angular)

I have such a code ng-init="validationRegex = '#RegularExpression.expression'" where RegularExpression.expression is c# string variable = "(\w+\/|\w+\\)+(\w+)\.\w+". I want to pass variable value to angular controller using ng-init. But in the end I get (w+/|w+\)+(w+).w+. How can I get right value?
I assume that your C# code is actually: #"(\w+\/|\w+\\)+(\w+)\.\w+". The # avoids needing the evil escaped escape.
You will likely need to use the evil escaped escape in this case. Note that you don't need to escape the / if you are putting it directly in a string (if you are using it how I think you are). You can also use braces to minimize the escaping. So you can take this regex:
(\w+/|\w+\\)+(\w+)[.]\w+
and pass it through regex planet to get this:
"(\\w+/|\\w+\\\\)+(\\w+)[.]\\w+"
I would not recommend manual conversion since you already have an escaped backslash.
Double escape the string using:
#RegularExpression.expression.Replace(#"\", #"\\")
When it comes through on the JavaScript side it will be singly-escaped again.

Drawing blanks in a textbox

I would like display, in a textbox, the spaces and the carriage return in order to show the user the exact test formatting, ie using a central point for spaces and an arrow for CRLF. Any idea ?
Eah, it's really hard! But you can replace spaces with some printable symblos for display purposes only. But carriage you shouldn't replace, just add new Symbols.
And before text usage, before writing to file for example, just convert all symbols back to spaces.
This solutiond of course, is not universal and complete.

Resources