How to remove everything but letters, numbers, space, exclamation and question mark from string?

You can use regex myString.replace(/[^\w\s!?]/g,”); This will replace everything but a word character, space, exclamation mark, or question. Character Class: \w stands for “word character”, usually [A-Za-z0-9_]. Notice the inclusion of the underscore and digits. \s stands for “whitespace character”. It includes [ \t\r\n]. If you don’t want the underscore, you can use just [A-Za-z0-9]. … Read more

Reading from property file containing utf 8 character

Use an InputStreamReader with Properties.load(Reader reader): FileInputStream input = new FileInputStream(new File(“uinsoaptest.properties”)); props.load(new InputStreamReader(input, Charset.forName(“UTF-8”))); As a method, this may resemble the following: private Properties read( final Path file ) throws IOException { final var properties = new Properties(); try( final var in = new InputStreamReader( new FileInputStream( file.toFile() ), StandardCharsets.UTF_8 ) ) { properties.load( … Read more

Using utf-8 characters in a Jinja2 template

TL;DR: Pass Unicode to template.render() Encode the rendered unicode result to a bytestring before writing it to a file This had me puzzled for a while. Because you do index_file.write( template.render(index_variables) ) in one statement, that’s basically just one line where Python is concerned, so the traceback you get is misleading: The exception I got … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)