简体   繁体   中英

How can I trim a string if input is Ramesh-123-india ...my desire output should be only "india""

In material table one of the column has to be trim..for example input is ramesh-123-india,the output should be come as only "india"....how to do this

Consider looking into the split() . JavaScript docs

You can pass in a string pattern that it searches for to split it up.

1) You can make use of split here

 const str = "ramesh-123-india"; const result = str.split("-")[2]; console.log(result);

2) You can also use regex /\w+$/ here as:

在此处输入图像描述

 const str = "ramesh-123-india"; const result = str.match(/\w+$/)[0]; console.log(result);

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