I am having trouble with a task which seemed very easy at first.
My aim is to create a simple js function, where the user can copy paste value from pdf onto a styled component input, then replace few words with blanks to create a clean json file.
Let's say I am trying to erase everything except the text "Lorem Ipsum" from
"Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum."
Here is what I tried, I am looking for ways to replace certain texts with blanks, and make it into json by separated by rows.
const [first, setFirst] = useState("");
return <Container type="text" placeholder="text here" onChange={(e)=>{setFirst(e.target.value);}}>
<div>{first}</div>
</Container>
The Container is a styled-input, and the div is just div.I want the div to show three Lorem Ipsum as an array, ready to be sliced and spliced.
Okay, I found it.
Replace works, yet does not work if syntax or line breaks are included, it will render an error instead.
My work around was to create multiple replace like: var xample = inputvalue.replace(/1|2|3/,",").replace(/4|5|6/,",")... if needed, you could add xample2 = xample.replace(//,"")...
and so on, the key was to be smart and create a specific algorithm dedicated to that specific content format.
For my case, I simply added split(',') so that the values are separated by comma.
Result would look similar to:
name:{xample2[0]}, address:{xample2[1]}:) hope it helps.