How to get the first word after dot bold in js

Related searches

how do i get the first word after dot in a sentence bold via javascript.


var text = "The quick brown fox jumps over the fence. hello world. please make every word after dot . bold"

Here's a quick solution:

var text = "The quick brown fox jumps over the fence. hello world. please make every word after dot . bold";


function getFirstWorkAfterDot(str) {
  return str.split(".")[1].split(" ")[1];

Styling First Word as Bold - HTML & CSS, I'm sure someone will post some kind of solution, but I have to ask… why not put some kind of tag (like <b>) around the names in the source? RyanReese August � The bold() method is not standard, and may not work as expected in all browsers. The bold() method is used to display a string in bold. This method returns the string embedded in the tag, like this: string

I assume that you're working with JavaScript that's going to output HTML, because, by itself, JavaScript doesn't know anything about text formatting.

You can do this using a regular expression replacement:

text.replace(/(?<=\. )(\S*)/g, "<b>$1</b>");

The /.../ is a regular expression literal. Regular expressions are really complicated, and it would take a long time to explain them fully, so I'll only explain the relevant bits to this particular expression (though if it interests you, I encourage you to look up more details).

The first bit ((?<=\. )) tells JS to look only for matches that are after a period and a space (make the space optional with (?<=\. ?). This is called a lookbehind.

The second bit ((\S*)) is a capture group that matches on any sequence of characters that aren't whitespace (\S). With a capture group, we can reuse this value in our replacement string.

The trailing g tells JS to replace all instances.

The second bit of the call to replace ("<b>$1</b>"), gives us $1, the value of the first capture group in our regular expression, and wraps it in an HTML <b> tag. If you're working in Node to produce command line output, you'll want to use "\033[1m$1\033[m" to wrap the value in ANSI escape codes.

Make the first word in a sentence bold, Hi, can anyone help me find the first word in a sentence and make it bold? I have been making it bold like this: <h2 class="font-light text-2x JavaScript has a String bold() Method. After function, and inspecting element, you get home Front End HTML CSS JavaScript HTML5 php.js Twitter Bootstrap Responsive Web Design tutorial Zurb Foundation Make first word bold of all elements


text.replace(/(\. *)(\w+)/g, "$1<b>$2</b>")

var text = "The quick brown fox jumps over the fence. hello world. please make every word after dot . bold"

msg.innerHTML = text.replace(/(\. *)(\w+)/g, "$1<b>$2</b>")
<div id="msg"></div>

Plain Text – Pug, Pug provides four ways of getting plain text — that is, any code or text content Plain text does still use tag and string interpolation, but the first word on the A good example is writing JavaScript and CSS code in the script and style tags. You can also create a dot block of plain text after other tags within the parent tag. Style the first word. To style the first word of a paragraph, we need to use some jquery code, since we don’t have a pseudo-element for this one. Here’s how you can accomplish it: $ ('p').each (function () { var word = $ (this).html (); var index = word.indexOf (' '); if (index == -1) { index = word.length; } $ (this).html ('<span class="first-word">' + word.substring (0, index) + '</span>' + word.substring (index, word.length)); });

get first letter of string javascript Code Example, Get code examples like "get first letter of string javascript" instantly right from your get data-letters javascript � jqueyr get part of string after first 3 charactrers� Well organized and easy to understand Web building tutorials with lots of examples of how to use HTML, CSS, JavaScript, SQL, PHP, Python, Bootstrap, Java and XML.

Selectors, E:first-child, Matches element E when E is the first child of its parent. Adjacent sibling selectors have the following syntax: E1 + E2, where E2 is the subject of the Note that the A:hover must be placed after the A:link and A:visited rules, since and thus the font weight of the first letter is normal, not bold as the SPAN: Whenever I need to get a class from a list of classes or a part of a class name or id, I always use split() then either get it specifically with the array index or, most often in my case, pop() to get the last element or shift() to get the first. This example gets the div's classes "gallery_148 ui-sortable" and returns the gallery id 148.

Looks good! But what if there are other chars before or after the word? Like @ or . or something something. Is it possible to grab all the content from the space before first word to the space after the word? So "this is some dummy to read" would" still result in "dummy to" but this way all other chars and words are included.

  • But how do you make it, so it works on every sentence in the text?