Help with the correct regular expression in PHP. I have a line (the chemical formula of a linear format) in which I want to replace the letter " H " (or) the letter " H ", followed by numbers.
For example:
CH3NO+ -> CNO+ C12H17ClN4OS -> C12ClN4OS CNO3 -> CNO3 H2O -> O CHO -> CO
This will be done:
$newVariable = preg_replace('~H\d*~', '', $yourVariable);
\d* means it will match if there are 0 or more matching digits.
\d*
Use this to solve your goal.
<?php $test = "CH3NO+"; echo preg_replace("/H\d+/i","",$test); ?>
Source: https://habr.com/ru/post/1623196/More articles:Gitlab CI with MATLAB - unit-testingNavigation menu items like Google Play Store - androidadding to UICollectionViewCell contentView via nib - iosPattern matching (any, any) as (string, string) does not work in case of a switch - string(Windows Phone 10) Можно ли редактировать, добавлять новые контакты программно в Windows Phone 10? - windowsCan functions be evaluated at compile time? - compiler-optimizationКак установить таймаут в CppUnitTestFramework (С++) в Visual Studio? - c++Open ELB accessible only from Gateway API - amazon-web-servicescp: can't stat 'share / docs / html: no such file or directory - couchdbUpdating 3 columns at the same time. 2nd table. - sqlAll Articles