简体   繁体   中英

How to delete a string characters until first caps character (javascript/jquery)

If i have paragraphs like so:

<p class="text">ats hjda syd This is the story of a lost programmer and his doubts about javascript..</p>

Ho can I tell using javascript or jquery, to delete from all p.text the first characters until it meets a caps character ("T" in this case)? Even regex would be ok i guess.

The number of characters before the first caps letter are variable.

The first caps letter varies, is different for each paragraph.

I know how to code the version which delete characters until a character is met but never had to deal with a variable caps character case like this.

UPDATE: the alternative i've got to achieve what i need, is to count the third space, cause the caps letter comes after three words all the times.

 const paragraphs = document.querySelectorAll('p'); paragraphs.forEach(paragraph => paragraph.innerText = paragraph.innerText.replace(/.*?([AZ].*)/, (a,b)=>b));
 <p class="text">ats hjda syd This is the story of a lost programmer and his doubts about The language Javascript..</p>

<script>



{
        let s = "<p class=ats hjda syd This is the story about javascript..</p>";
        let p = /.*([A-Z].*)/;
        let t = s.match(p);
        
        if (t != null) {// OK
            alert(t[1]); // extracted string
        }
        else alert('nok'); //no match
    }       
  </script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM