Word count regex in HTML [closed] - html

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed last month.
Improve this question
This is the same question as this. But since I'm not using javascript, 'innerText' is not a solution for me and I was wondering if it was possible for regex to combine /(<.*?>)/g and /\S+/g to get the actual word count without having to make a bunch of string operations.
The language I'm using here is Dart, if a solution I haven't found already exist within it that would work too as an answer. Thanks !
Edit : Someone edited the tags ? This question is not Dart-specific and is about regex, so I'm putting them back as they were.
Edit 2 : The question was closed because it is not "focused", but I do not know how I can make "if it was possible for regex to combine /(<.*?>)/g and /\S+/g" any more focused.

Assuming all text is enclosed in HTML elements, you can use (?<=>|\s)[^<\s>='"]+?(?=<|\s).
With the string <p>One</p><p>Two Three, Four. Five</p><p>Six</p> there are six matches.
Note:
It uses a lookbehind group, which might not be supported in all browsers.
Punctuation at the end of words are grouped with them, e.g. "three," so keep that in mind if you're planning to use the actual words and not just count them.

Related

What Unicode character represents "Add User/Account" [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 years ago.
Improve this question
As the Title says, I want to have a button in HTML which should add users to my database. Alright, I have that. Now I want it to display a symbol representing this feature. I only want to use images as a last resort. So do you have any suggestions for my needs? Haven't found anything by simply asking Google.
To be specific, the character should have a silhouette of an upper body and a plus sign.
There are a couple of Unicode symbols which look like "user".
👤
U+1F464 Bust in Silhouette
👥
U+1F465 Busts in Silhouette
You will need to test with users to see which they associate more with "Add User". You might need to use a couple of characters. For example
👤➕
🆕👤
Or, if your users are technologists, doctors, students etc you could use their emoji.
👩‍💻 👩‍⚕️ 👩‍🎓
As of Unicode 12.1, there is no such symbol expressing this meaning.
Do use an image, e.g. https://material.io/resources/icons/static/icons/baseline-person_add-24px.svg

I wanted my input box to accept pattern like txt.txt.txt if its char and 11.22.33.44.55 [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I am looking for regular expression which should fullfill my below condition
Condition1 - If its character set then its should restrict to three dots only like
xyx.fff.gsd should display error if it have more than three dots
Condition2 - But if its with digits then it should not restrict the limit
1.2.3.4.5.6.7.8 so on
Currently I am using ^([0-9A-Za-z_-]+.[0-9A-Za-z_-]+.[0-9A-Za-z_]+)$ RegEx but its fulfilling my Condition1 only not 2
Can anyone please help
Hello and welcome to StackOverflow.
Since you put the HTML tag, I guess you want to use JavaScript for your regular expression.
To build a regular expression, a good start would be to identify exactly what you want to match, if possible without examples.
If I understand you correctly, you want your regex to match those 2 cases :
exactly 3 groups of exactly 3 letters, each separated by a dot
multiple groups of numbers with a dot between them
Now that this is established, you can start building your regular expression.
I think something like this might fit :
^((\d+(\.\d+){2,})|([\w\d_-]+(\.[\w\d_-]+){2}))$
You can test it on Regex101
Edit : Changed the regex according to the comments below

Ads filtering server side [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I'm working on a web application where I display HTML from other websites. Before displaying the final version I'd like to get rid of the ads.
Any ideas, suggestions on how to accomplish this? it doesn't need to be a super efficient filtering tool, I was thinking in porting some of the filters defined by adblockplus to Ruby and return the parsed doc with some help of Nokogiri.
Let's say I use the super wildcard filter ad. That's not an official adblock but for simplicity I'll use it here. The idea then would be to remove all the elements for which any of the attributes match the filter, e.g: src="http://ad.foo.com?my-ad.gif" href="http://ad.foo.com" class="annoying-ad" etc.
The Nokogiri command for this filter would be:
doc.xpath("//*[#*[contains(., 'ad')]]").each { |element| element.remove }
I applied the filter for this page:
And the result was:
Not that bad, note that the global wildcard filter also got rid of valid elements like headers because they have attributes like id="masthead".
So I think this approach is ok for my case, now the question would be what filters to use? they have a huge list of filters and I don't feel like iterating over all of them. I'm thinking in grabbing the top 10-20 and parse the docs based on that, is there a list out there with the most popular ones? If so, I haven't been able to find it.

adding html attributes without a value using .net [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I want to add a multiple attribute to a select in .net. I have done this:
If MultiSelect Then
drpSelect.Attributes.Add("multiple", "true")
End If
Though strictly speaking the html should be just multiple.
For the "boolean" html attributes (the ones that should consist of just a name without a value, like required or multiple) an accepted alternative is to use name="name", like multiple="multiple".
In your case you should code
drpSelect.Attributes.Add("multiple", "multiple")
See also W3C:
Boolean attributes may legally take a single value: the name of the
attribute itself.

Regular expression to replace <br style="..."> by <br style="..."/> [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I need a regular expression to help me close the <br> tag to comply with the xhtml standard. In my html br does not always comes empty, so the regex has to account for it. Thanks in advance for your help.
Look for this pattern
(\<br[^\>]*)(\/)?(\>)
And replace with this
$1/$3
Based on the engine you may need to use \1/\2 instead of $1/$3 in the replacement string.
The regex might also look a bit simpler:
replace
/<br.*?>/i
with
<br\/>